Getting the number of comp in an Assembly as a count

85 views
Skip to first unread message

Rodney Michels

unread,
Jul 31, 2009, 3:54:19 PM7/31/09
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

Rodney Michels

unread,
Jul 31, 2009, 4:21:06 PM7/31/09
to SolidWorks-API
I figured it out.

Thanks anyway,
Rodney

Reply all
Reply to author
Forward
0 new messages