Rodney Michels
unread,Jul 31, 2009, 3:54:19 PM7/31/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to SolidWorks-API
Can anyone lead me down a better path? I am currently using
Solidworks example to traverse an assembly for all its components.
Here is the code...
Option Explicit
Sub TraverseComponent _
( _
swComp As SldWorks.Component2, _
nLevel As Long _
)
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim swCompConfig As SldWorks.Configuration
Dim sPadStr As String
Dim i As Long
For i = 0 To nLevel - 1
sPadStr = sPadStr + " "
Next i
vChildComp = swComp.GetChildren
For i = 0 To UBound(vChildComp)
Set swChildComp = vChildComp(i)
TraverseComponent swChildComp, nLevel + 1
Debug.Print sPadStr & swChildComp.Name2 & " <" &
swChildComp.ReferencedConfiguration & ">"
Next i
End Sub
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swConf As SldWorks.configuration
Dim swRootComp As SldWorks.Component2
Dim bRet As Boolean
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent
Debug.Print "File = " & swModel.GetPathName
TraverseComponent swRootComp, 1
End Sub
'---------------------------------------
My problem is, I want to get a count. So if the Assembly had 500
components in it, I want to get that number and store it into a
varible.
HELP???
Thanks,
Rodney