Hi,
I have to check some "properties" on all components in an opened assembly (loop through all sub-assembly level).
I created a loop for it, and first of all I have to check the name and if current component is assembly or not?
This seem easy at first sight but I stucked, because if the "inspected" component is virtual and suppressed, I have no idea how to get these informations.
This is a shoerened code with "looper" function:
Option Explicit
Public swApp As SldWorks.SldWorks
Public swModel As ModelDoc2
Sub Main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
LevelLoop swModel 'first call of "looper" with currently opened assembly
End Sub
Function LevelLoop(swModelBase As ModelDoc2)
Dim vComps As Variant
Dim swAssy As SldWorks.AssemblyDoc
Dim swComp As SldWorks.Component2
Dim swModel As ModelDoc2
Dim i As Integer
Dim name As String
Dim compType as String
If swModelBase.GetType = swDocASSEMBLY Then
Set swAssy = swModelBase
vComps = swAssy.GetComponents(True)
If Not IsEmpty(vComps) Then
For i = 0 To UBound(vComps) 'loop through all of current asm's components
Set swComp = vComps(i)
Set swModel = swComp.GetModelDoc2
'get component name and type..
If swComp.GetSuppression <> 0 Then
'if component is RESOLVED or VIRTUAL, "swComp.Name" and "swModel.GetType" works
name = swComp.Name
If swModel.GetType = swDocASSEMBLY Then compType = "ASM" Else compType = ""
Else
'if component is SUPPRESSED, "swComp.Name" and "swModel.GetType" doesn't works,
'therefore that was my idea to decide component asm or not, but VIRTUAL components has no path :/
name = swComp.GetPathName
If UCase(Right(swComp.GetPathName, 6)) = "SLDASM" Then compType = "ASM" Else compType = ""
End If
If compType = "ASM" Then
If swComp.GetSuppression <> 0 Then
DoSomething
LevelLoop swModel 'the looper function "goes inside" of the current assembly
End If
End If
Next i
End If
End If
End Function
Anybody has any idea?
Thank you
SolidworksApi macros