I got the XML code to output the properties of parts and assembly using VBA macro in SOlidworks. In my assembly , there are 3 parts. This is some part of my VBA code in assembly.
.....
Set swAssembly = swModel
Set swCustPropMgr = swAssembly.Extension.CustomPropertyManager("")
Dim components As Variant
components = swAssembly.GetComponents(False)
' Check if the components array is not empty
If Not IsEmpty(components) Then
' Get the count of components
partsCount = UBound(components) - LBound(components) + 1
Else
' Handle the case where there are no components in the assembly
End If
' Loop through all the components in the assembly and add their properties to the XML code
For i = 0 To partsCount - 1
Set swComp = swAssembly.GetComponents(False)(i)
Debug.Print "component:" & swComp.Name
If Not swComp Is Nothing Then
Set swPart = swComp.GetModelDoc2
' Get the custom property manager for the component
Set swCustPropMgr = swPart.Extension.CustomPropertyManager("")
' Get the value of a specific property by name
partNum = swComp.Name
partNum = Left(partNum, Len(partNum) - 2)
qty = 1
Dim Color As String
Color = swCustPropMgr.Get("Color")
Material = swCustPropMgr.Get("Material")
finish = swCustPropMgr.Get("Finish")
Process = swCustPropMgr.Get("Process")
.....
Here, qty is the count of the same parts in assembly and I am trying to get the count but I didn't yet. I want the vba code to get it. Also, in above code, when i = 0, current swComp indicates the third part in assembly, not first part. But I have to indicate the first part. If I add the forth part in assembly, the part is located in forth position exactly in the outputted XML code. The names of parts is like this. Part_A, Part_B, Part_C(current vba code indicate Part_C when i = 0 and Part_A when i = 1, and then Part_B when i=2) I want to know why this happened. Thanks for your time Kostiantyn
To get the components in the Feature tree order with their quantity, you will need to get them from the assembly features, like so:
Create a new class with: Insert > Class Module