Bonjour,
Je suis novice en programmation, je souhaiterai modifier les propriétés personnalisées des pièces ou des assemblages solidworks via une macro.
Par exemple, Dessinateur=XXX, Nom du projet=XXXX.
Pouvez vous m'aider s'il vous plait?
Bonjour,
Je suis novice en programmation, je souhaiterai modifier les propriétés personnalisées des pièces ou des assemblages solidworks via une macro.
Par exemple, Dessinateur=XXX, Nom du projet=XXXX.
Pouvez vous m'aider s'il vous plait?
Bonjour,
Tu peux aussi essayer ça :
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
Cordialement,
J'ai une " erreur d'execution '438': Propriété ou méthode non gérée par cet objet" quand je tape :
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