Makro do edycji właściwości niestandardowych

Witam

Jestem nowicjuszem w programowaniu, chciałbym modyfikować niestandardowe właściwości części lub złożeń solidworks za pomocą makra.

Na przykład Kreślarz=XXX, Nazwa projektu=XXXX.

Czy możesz mi pomóc?

Witam

Przykład znajdziesz TUTAJ , który powinien pozwolić Ci robić to, na co masz ochotę.

Pozdrowienia

1 polubienie

Witam

Możesz również spróbować tego:

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

Pozdrowienia

Mam "błąd wykonania '438': Właściwość lub metoda nie jest obsługiwana przez ten obiekt" po wpisaniu :

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