Hello @Cyril.f
The macro only works if I create the SURFACE PIECE property in F8.
If the field is not created, nothing happens.
I've been looking for how to create the field automatically, but I'm stuck.
Here's what I tried to tinker with without success:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Sun sMass As String
Dim sValout As String
Dim sVal As String
Dim bRet As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("PC") 'If the property is in the customize tab, leave blank by replacing 'PC' with ''
bRet = swCustProp.Get6', False, sValout, sMasse, False, False) 'Retrieving the mass property, changing the name of the property to suit your model
sVal = CStr(CDec(sMass) * 2) 'Convert text to decimal value, multiply x RATIO and convert to text data
'bRet = swCustProp.Set2("SURFACE PIECE", sVal) 'Populate the SURFACE PIECE property with the value converted to text
bRet = swModel.AddCustomInfo3("PC", "SURFACE PIECE", val)
End Sub
I tried with this command, but I think something is wrong:
bRet = swModel.AddCustomInfo3("PC", "SURFACE PIECE", val)
Do you have an idea to correct this please?