MACRO LIBRARY

Move all configuration specific custom properties to document custom properties

Free public access. No account or subscription required.

Files

Move all configuration specific custom properties to document custom properties

Code

'Move all configuration specific custom properties to document custom properties
    
'Preconditions: part is open
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDocCustPropMgr As SldWorks.CustomPropertyManager
Dim swConfigCustPropMgr As SldWorks.CustomPropertyManager
    
Dim vConfigNames As Variant
Dim vDocCustPropNames As Variant
    
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim blnExists As Boolean
    
Dim strValue As String
Dim strResValue As String
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
    'get document custom property manager
    Set swDocCustPropMgr = swModel.Extension.CustomPropertyManager(Empty)
    vDocCustPropNames = swDocCustPropMgr.GetNames
    
    'get config specific custom properties
    vConfigNames = swModel.GetConfigurationNames
    For i = 0 To UBound(vConfigNames)
        Set swConfigCustPropMgr = swModel.Extension.CustomPropertyManager(vConfigNames(i))
        vConfigCustPropNames = swConfigCustPropMgr.GetNames
        If IsEmpty(vConfigCustPropNames) = False Then
            For j = 0 To UBound(vConfigCustPropNames)
                swConfigCustPropMgr.Get3 vConfigCustPropNames(j), True, strValue, strResValue
                'get the config specific cust prop and see if it is present at the _
                    config specific level
                blnExists = False
                For k = 0 To UBound(vDocCustPropNames)
                    If vConfigCustPropNames(j) = vDocCustPropNames(k) Then blnExists = True
                Next k
                'add the config specific custom property if it wasn't present
                If blnExists = False Then _
                    swDocCustPropMgr.Add2 vConfigCustPropNames(j), swCustomInfoText, strValue
                'delete the config specific custom property
                swConfigCustPropMgr.Delete vConfigCustPropNames(j)
            Next j
        End If
    Next i
End Sub