Hello
I am a novice in programming, I would like to modify the custom properties of solidworks parts or assemblies via a macro.
For example, Draftsman=XXX, Project Name=XXXX.
Can you help me please?
Hello
I am a novice in programming, I would like to modify the custom properties of solidworks parts or assemblies via a macro.
For example, Draftsman=XXX, Project Name=XXXX.
Can you help me please?
Hello
You can also try this:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swConfig As SldWorks.Configuration
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim configNames As Variant
Dim configName As Variant
Dim lRetVal As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'Pour l'onglet "personnaliser"
Set swCustPropMgr = swModel.Extension.CustomPropertyManager(Empty)
lRetVal = swCustPropMgr.Add3("Dessinateur", swCustomInfoType_e.swCustomInfoText, "XXX", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
lRetVal = swCustPropMgr.Add3("Nom du projet", swCustomInfoType_e.swCustomInfoText, "XXX", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
'Pour toutes les configurations du modèle 3D
configNames = swModel.GetConfigurationNames
For Each configName In configNames
Set swConfig = swModel.GetConfigurationByName(configName)
Set swCustPropMgr = swConfig.CustomPropertyManager
lRetVal = swCustPropMgr.Add3("Dessinateur", swCustomInfoType_e.swCustomInfoText, "XXX", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
lRetVal = swCustPropMgr.Add3("Nom du projet", swCustomInfoType_e.swCustomInfoText, "XXX", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
Next
End Sub
Kind regards
I have a "run-time error '438': Property or method not handled by this object" when I type:
Dim ValOut As String
Dim ResolvedValOut As String
Dim wasResolved As Boolean
Dim linkToProp As Boolean
Dim resolved As Variant
Dim linkProp As Variant
Dim nNbrProps As Long
Dim j As Long
Dim custPropType As Long
Dim bRet As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set config = swModel.GetActiveConfiguration
Set cusPropMgr = config.CustomPropertyManager
lRetVal = cusPropMgr.Add3("Dessinateur", swCustomInfoType_e.swCustomInfoDate, "XXX", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
lRetVal = cusPropMgr.Get6("Dessinateur", False, ValOut, ResolvedValOut, wasResolved, linkToProp)
bRet = cusPropMgr.IsCustomPropertyEditable("Dessinateur", config.Name)
If bRet = 0 Then
Debug.Print " Dessinateur is editable."
lRetVal = cusPropMgr.Set2("Dessinateur", "ATB")
Else
Debug.Print " Dessinateur is not editable."
End If
lRetVal = cusPropMgr.Get6("Dessinateur", False, ValOut, ResolvedValOut, wasResolved, linkToProp)
' Get the number of custom properties for this configuration
nNbrProps = cusPropMgr.Count
Debug.Print "Number of properties for this configuration: " & nNbrProps
' Gets the custom properties
lRetVal = cusPropMgr.GetAll3(vPropNames, vPropTypes, vPropValues, resolved, linkProp)
' For each custom property, print its name, type, and evaluated value
For j = 0 To nNbrProps - 1
custPropType = cusPropMgr.GetType2(vPropNames(j))
Debug.Print " Name, swCustomInfoType_e value, and resolved value: " & vPropNames(j) & ", "; custPropType & ", " & vPropValues(j)
Next j
' Get the number of custom properties for this configuration
nNbrProps = cusPropMgr.Count
Debug.Print "Number of properties for this configuration: " & nNbrProps
End Sub