This macro works as follows:
1. Part must be open.
2. If a property called "Material" already exists at the doc level (custom tab), that property will be replaced with the new one.
3. If a property called "Material" doesn't exist at the doc level, it will be added.
4. The property always refers to the active config's material.
Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swCustPropMgr As SldWorks.CustomPropertyManager Dim strActiveConfig As String Dim strValue As String Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swCustPropMgr = swModel.Extension.CustomPropertyManager(Empty) strActiveConfig = swModel.ConfigurationManager.ActiveConfiguration.Name strValue = Chr(34) & "SW-Material" & Chr(34) swCustPropMgr.Add3 "Material", swCustomInfoText, strValue, swCustomPropertyReplaceValue End Sub
Thank you! This works exactly how I needed it.
Great. Can you please mark my answer as correct? I would greatly appreciate it.