AnsweredAssumed Answered

Adding custom properties (mass, and materials) for BOM for every part in asbly

Question asked by Benjamin Whiffen on Oct 31, 2019

I would like to add custom properties to all parts in an assemble, mass and material see pic for example. I want to do this so the weight and material can be in the BOM, I already made the assembly and parts so I cant use a template and don't want to spend hours going through hundreds of parts changing that.


I have tried to use a macro from the bottom of this, and try to modify it to put the mass and material but i cant get it to work.

batch Add custom property to all assembly components using macro 


This is what I changed: I can't figure out what is wrong and I have no idea what I'm doing.

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim vComps As Variant
Dim swComp As SldWorks.Component2
Dim swAssy As SldWorks.AssemblyDoc
Dim i As Integer

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

updateProperty swModel

If swModel.GetType = swDocASSEMBLY Then
Set swAssy = swModel
vComps = swAssy.GetComponents(False)
For i = 0 To UBound(vComps)
Set swComp = vComps(i)
If swComp.GetSuppression = swComponentFullyResolved Then
Set swModel = swComp.GetModelDoc2
updateProperty swModel
End If
Next i
End If

End Sub

Function updateProperty(swModel As SldWorks.ModelDoc2) As Boolean
Dim cpm As CustomPropertyManager
Dim path As String, filename As String, Description As String
Set cpm = swModel.Extension.CustomPropertyManager("")

'cpm.Delete "Test"
cpm.Add2 "Mass", swCustomInfoText, Chr(34) + "SW-Mass" + "@@" + "swComp" + "@" + "filename" + Chr(34)

End Function


Thank you for your help