Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Application Event: OnOpenDocument

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
ndillner343SKL
285 Views, 2 Replies

Application Event: OnOpenDocument

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

 

 

 

 

2 REPLIES 2
Message 2 of 3

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...

Message 3 of 3

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report