I'm trying to write a macro that creates a list of all components in an assembly and does some actions on each one.
As you see in the following images, the list that macro gives me is not in the order of the components in feature manager.
How can I have the given list match the order of the components in feature manager.
thanks for any kind of help.
this is the macro:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim strValue0 As String
Dim strValue1 As String
Dim strValue2 As String
Dim strValue3 As String
Dim strValue4 As String
Dim strValue5 As String
Dim swBodyFolder As SldWorks.BodyFolder
Sub main()
Dim swModel As ModelDoc2
Dim swModel_Assy As ModelDoc2
Dim vComps As Variant
Dim swComp As SldWorks.Component2
Dim swAssy As SldWorks.AssemblyDoc
Dim i As Integer
Dim PN As String
Dim Result As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModel_Assy = swApp.ActiveDoc
If swModel.GetType = swDocASSEMBLY Then
Set swAssy = swModel
vComps = swAssy.GetComponents(False)
For i = 0 To UBound(vComps)
Set swComp = vComps(i)
Set swModel = swComp.GetModelDoc2
Debug.Print swModel.GetTitle
' some actions here .....
Next i
End If
End Sub
SolidworksApi macros