Hi, I would like to write a macro that would add the property "Espessura" to all the parts in the assembly i run it. The property "Espessura" would be the value of the Equation "Espessura" which solidworks provides by default
Try the macro by Ivana Kolin here Add custom property to all assembly components using macro and then modify as needed.
In case you need option to input the custom property name or it's value then check here Add custom property to all assembly components using macro and Input Box
What i need to do is add a custom property with the "Espessura@*Partname*.SLDPRT". How can i write that in the macro? Which things should i replace? Sorry, i'm a beginner in macro writing
Make these two changes:
Change this line
wo_num = "Espessura"
And change this line
cpm.Add3 mValue, swCustomInfoText, Chr(34) & mValue & "@" & swModel.GetTitle & ".SLDPRT" & Chr(34), 1
im trying to edit this to add sw-mass as the value and weight as the property name.
and additional set the units of the part to kilograms.
on new part i have this set up, but need to add this to lots add this to lots legacy parts.
code i have so far but not quite working.
Option ExplicitDim swApp As SldWorks.SldWorksDim swModel As ModelDoc2Dim vComps As VariantDim swComp As SldWorks.Component2Dim swAssy As SldWorks.AssemblyDocDim i As IntegerDim wo_num As StringDim strfilename As String
Sub main()Set swApp = Application.SldWorksSet swModel = swApp.ActiveDocwo_num = "SW-Mass" & "@" & swModel.GetTitle
updateProperty swModel, wo_num 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, wo_num Else MsgBox "warn user lightweight or suppressed" End If Next iEnd IfEnd Sub Function updateProperty(swModel As SldWorks.ModelDoc2, mValue As String) As BooleanDim cpm As CustomPropertyManagerSet cpm = swModel.Extension.CustomPropertyManager("")cpm.Add3 "Weight", swCustomInfoText, mValue, 1End Function
Try this line wo_num = Chr(34) + "SW-Mass" + Chr(34)
Retrieving data ...