Copy iProperties of Model Document to Drawing Document When Placing View

By Xiaodong Liang

Question:
Within the document settings for a drawing, on the drawing tab, there is a button called "Copy Model iProperty Settings… " this brings you to the settings dialog box which has a check box to enable Copy Model iProperties. Checking the box will enable a list of iProperties found in the drawing which you would like to enable inventor to copy from the model to the drawing’s iProperties.

I am looking for a way within the API to check the box highlighted in red and then any iProperties in the list.

image

Solution:
The DrawingSettings object has not exposed the relevant API to toogle the [Copy Model Properties]. But with current API, it is feasible to implement the copying when placing the drawing view. The following is a VBA code demo which watches the event of document changing. If it is “Create Drawing View”, get the model document of the drawing view, and copy the specific iProperties to the drawing document.

Module:

Private cls As clsDocEvent
Sub startcmd()
    Set cls = New clsDocEvent
End Sub

Sub Endcmd()
    Set cls = Nothing
End Sub

Event Class:

‘document event
Private WithEvents DocEvts As DocumentEvents
‘current drawing document
Private thisDrawingDoc As DrawingDocument

Private Sub Class_Initialize()
    ‘get the current document
    Set thisDrawingDoc = ThisApplication.ActiveDocument
    ‘get document event
    Set DocEvts = thisDrawingDoc.DocumentEvents
  
End Sub

Private Sub Class_Terminate()
    Set DocEvts = Nothing
End Sub

Private Sub DocEvts_OnChange(ByVal ReasonsForChange As CommandTypesEnum, _
            ByVal BeforeOrAfter As EventTimingEnum, _
            ByVal Context As NameValueMap, _
            HandlingCode As HandlingCodeEnum)

If BeforeOrAfter = kAfter Then
       
        ‘check the context
        Dim i As Integer
        Dim oEachObj As Variant
        For i = 1 To Context.Count
      
       On Error Resume Next
       Set oEachObj = Context.Item(i)
      
       If Err Then
         Dim oName As String
         oName = Context.Item(i)
        
         ‘if this is fired by placing drawing view
         If oName = "Create Drawing View" Then
           
            ‘get the document the drawing view refers to
            Dim oLastView As DrawingView
            Set oLastView = thisDrawingDoc.ActiveSheet.DrawingViews(thisDrawingDoc.ActiveSheet.DrawingViews.Count)
           
            Dim oRefDoc As Document
            Set oRefDoc = oLastView.ReferencedDocumentDescriptor.ReferencedDocument
           
            ‘copy some specific iProperties to the drawing document
           
            ‘ document title
             Dim oTitle As String
             oTitle = oRefDoc.PropertySets("Summary Information").ItemByPropId(kTitleSummaryInformation).value
             ‘copy to drawing document
             thisDrawingDoc.PropertySets("Summary Information").ItemByPropId(kTitleSummaryInformation).value = oTitle
           
            ‘ document description
              Dim oDesc As String
             oDesc = oRefDoc.PropertySets("Design Tracking Properties").ItemByPropId(kDescriptionDesignTrackingProperties).value
              ‘copy to drawing document
             thisDrawingDoc.PropertySets("Design Tracking Properties").ItemByPropId(kDescriptionDesignTrackingProperties).value = oDesc
         End If
        
         Err.Clear
       Else
          ‘if context item is also a NamedValueMap
       End If
    
    Next
  
    End If
End Sub


Comments

2 responses to “Copy iProperties of Model Document to Drawing Document When Placing View”

  1. Would you please show how this VBA code would be entered into Inventor? I would like to use it but I must not be entering it correctly as it gives me errors.
    Thanks

  2. Hi John,
    sounds like you may not be familiar with ‘event’ in VBA? probably after reading the following blog, you would be able to figure it out the issue?
    http://blogs.msdn.com/b/project_programmability/archive/2007/02/12/vba-event-handler-example.aspx

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading