Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim cusPropMgr As SldWorks.CustomPropertyManager
Dim bret As Boolean
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set cusPropMgr = swModelDocExt.CustomPropertyManager("")
bret = cusPropMgr.Add3("Designation4", swCustomInfoType_e.swCustomInfoText, "test Designation 4", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
End Sub
Dus om een eigenschap toe te voegen, de waarde van een eigenschap te lezen en een eigenschap te verwijderen, kunnen we doen:
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim config As SldWorks.Configuration
Dim cusPropMgr As SldWorks.CustomPropertyManager
Dim bret As Boolean
Dim lRetVal As Long
Dim ValOut As String
Dim ResolvedValOut As String
Dim wasResolved As Boolean
Dim nNbrProps As Long
Dim vPropNames As Variant
Dim vPropTypes As Variant
Dim vPropValues As Variant
Dim resolved As Variant
Dim custPropType As Long
Dim K As Long
Dim NomProperty As String
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set cusPropMgr = swModelDocExt.CustomPropertyManager("")
' On ajoute une propriété
bret = cusPropMgr.Add3("Designation5", swCustomInfoType_e.swCustomInfoText, "test Designation5", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
nNbrProps = cusPropMgr.Count
vPropNames = cusPropMgr.GetNames
For K = 0 To nNbrProps - 1
cusPropMgr.Get2 vPropNames(K), ValOut, ResolvedValOut
custPropType = cusPropMgr.GetType2(vPropNames(K))
' On relève la valeur de la propriété "Designation5"
If vPropNames(K) = "Designation5" Then
NomProperty = ResolvedValOut
MsgBox NomProperty
End If
' On supprime la propriété "Designation5"
If vPropNames(K) = "Designation5" Then
cusPropMgr.Delete (vPropNames(K))
End If
Next K
End Sub
Bedankt D. Roger voor je beloning, het werkt behalve voor de waarden van eigenschappen die aanhalingstekens bevatten, bijvoorbeeld " $PRP: "SW-File Name", in de macro defaults "compilatiefout Expected list separator of )", Ik begrijp het probleem goed wat er in de eigenschappen staat "mengt" met de VB-code hoe ik het kan vertellen dat de aanhalingstekens dat niet doen Geen onderdeel van de code, maar van de waarde die in de doos moet worden geschreven?