MACRO LIBRARY

Copy drawing custom properties to part or assembly

Free public access. No account or subscription required.

Instructions

Copy drawing custom properties to the model referenced in selected drawing view.

Preconditions
drawing is open and view is selected.
Result
drawing custom properties are copied to model referenced in selected view.

Files

Copy drawing custom properties to part or assembly

Code

'Copy drawing custom properties to the model referenced in selected drawing view
    
'Preconditions: drawing is open and view is selected
'Results: drawing custom properties are copied to model referenced in selected view
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDrawCustPropMgr As SldWorks.CustomPropertyManager
Dim swModelCustPropMgr As SldWorks.CustomPropertyManager
Dim swView As SldWorks.View
Dim swViewModel As SldWorks.ModelDoc2
Dim strExtension As String
Dim vCustPropNames As Variant
Dim i As Integer
Dim strValOut As String
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDrawCustPropMgr = swModel.Extension.CustomPropertyManager(Empty)
    
    Set swSelMgr = swModel.SelectionManager
    If swSelMgr.GetSelectedObjectType3(1, -1) = swSelDRAWINGVIEWS Then
        Set swView = swSelMgr.GetSelectedObject6(1, -1)
        
        strExtension = Right(UCase(swView.GetReferencedModelName), 6)
        If strExtension = "SLDPRT" Then
            Set swViewModel = swApp.OpenDoc6(swView.GetReferencedModelName, swDocPART, _
                swOpenDocOptions_Silent, Empty, Empty, Empty)
        ElseIf strExtension = "SLDASM" Then
            Set swViewModel = swApp.OpenDoc6(swView.GetReferencedModelName, swDocPART, _
                swOpenDocOptions_Silent, Empty, Empty, Empty)
        End If
        
        Set swModelCustPropMgr = swViewModel.Extension.CustomPropertyManager(Empty)
        vCustPropNames = swDrawCustPropMgr.GetNames
        For i = 0 To UBound(vCustPropNames)
            swDrawCustPropMgr.Get4 vCustPropNames(i), True, strValOut, Empty
            swModelCustPropMgr.Add2 vCustPropNames(i), swCustomInfoText, strValOut
        Next i
    End If
End Sub