Application Event: OnOpenDocument

Application Event: OnOpenDocument

ndillner343SKL
Enthusiast Enthusiast
439 Views
2 Replies
Message 1 of 3

Application Event: OnOpenDocument

ndillner343SKL
Enthusiast
Enthusiast

Hello,

 

I'm trying to run the rule below upon opening a document. But whenever I open a document, the rule runs twice. How do I make this sub routine only run once within the document being opened?

 

 

 

Private Sub m_ApplicationEvents_OnOpenDocument() Handles m_ApplicationEvents.OnOpenDocument
    Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
    Select Case True
        Case oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject
            MsgBox("Open: I am a Part | " & oDoc.DisplayName)
        Case oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject
            MsgBox("Open: I am a Assembly | " & oDoc.DisplayName)
        Case oDoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject
            MsgBox("Open: I am a Drawing | " & oDoc.DisplayName)
    End Select
End Sub

 

 

 

 

0 Likes
Accepted solutions (2)
440 Views
2 Replies
Replies (2)
Message 2 of 3

ndillner343SKL
Enthusiast
Enthusiast
Accepted solution

Never mind, this did the trick.

 

Private Sub m_ApplicationEvents_OnOpenDocument(ByVal DocumentObject As Inventor._Document, ByVal FullDocumentName As String,
    ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_ApplicationEvents.OnOpenDocument
    If Not BeforeOrAfter = 4098 Then Exit Sub
    Select Case True
        Case DocumentObject.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject
            MsgBox("Open: I am a Part | " & FullDocumentName)
        Case DocumentObject.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject
            MsgBox("Open: I am a Assembly | " & FullDocumentName)
        Case DocumentObject.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject
            MsgBox("Open: I am a Drawing | " & FullDocumentName)
    End Select
End Sub

 

 

Source:

https://forums.autodesk.com/t5/inventor-programming-ilogic/canceling-the-onopendocument-event-before...

0 Likes
Message 3 of 3

Frederick_Law
Mentor
Mentor
Accepted solution

You can use EventTimingEnum:

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-53FA7C91-113E-44E6-A515-9FBFCA415E35

 

Private Sub m_ApplicationEvents_OnOpenDocument(ByVal DocumentObject As Inventor._Document, ByVal FullDocumentName As String,
    ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_ApplicationEvents.OnOpenDocument
    If BeforeOrAfter = EventTimingEnum.kAfter Then
        Select Case True
        Case DocumentObject.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject
            MsgBox("Open: I am a Part | " & FullDocumentName)
        Case DocumentObject.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject
            MsgBox("Open: I am a Assembly | " & FullDocumentName)
        Case DocumentObject.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject
            MsgBox("Open: I am a Drawing | " & FullDocumentName)
        End Select
    End If
End Sub
0 Likes