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
Solved! Go to Solution.
Solved by Frederick_Law. Go to Solution.
Solved by ndillner343SKL. Go to 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:
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.