Goodmorning,
We got a standalone program at work for inventor. In the program we can do different things with inventor. But the one thing we need is to get the name of the active document without having to click at a button or something. I can't get it to work. The current code is this:
Public Class Form5
Private WithEvents m_onDocumentChangeEvent As Inventor.ApplicationEvents
Private WithEvents m_appEvents As Inventor.ApplicationEvents
Private g_inventorApplication As Inventor.Application
Private DocumentObject As Inventor.Document
Public Sub ActiveEvents()
g_inventorApplication = Marshal.GetActiveObject("Inventor.Application")
DocumentObject = g_inventorApplication.ActiveDocument
m_onDocumentChangeEvent = g_inventorApplication.ApplicationEvents
m_appEvents = g_inventorApplication.ApplicationEvents
End Sub
Private Sub m_onDocumentChangeEvent_OnDocumentChange(ByVal DocumentObject As Inventor.Document,
ByVal BeforeOrAfter As EventTimingEnum,
ByVal ReasonsForChange As CommandTypesEnum,
ByVal Context As NameValueMap,
ByRef HandlingCode As HandlingCodeEnum) Handles m_onDocumentChangeEvent.OnDocumentChange
If BeforeOrAfter = EventTimingEnum.kAfter Then
MsgBox("OnActivateDocument " & DocumentObject.DisplayName)
End If
Label1.Text = "Inventor document name"
End Sub
End Class
Is it possible to change the label name when I change the the document"??
Solved! Go to Solution.
Goodmorning,
We got a standalone program at work for inventor. In the program we can do different things with inventor. But the one thing we need is to get the name of the active document without having to click at a button or something. I can't get it to work. The current code is this:
Public Class Form5
Private WithEvents m_onDocumentChangeEvent As Inventor.ApplicationEvents
Private WithEvents m_appEvents As Inventor.ApplicationEvents
Private g_inventorApplication As Inventor.Application
Private DocumentObject As Inventor.Document
Public Sub ActiveEvents()
g_inventorApplication = Marshal.GetActiveObject("Inventor.Application")
DocumentObject = g_inventorApplication.ActiveDocument
m_onDocumentChangeEvent = g_inventorApplication.ApplicationEvents
m_appEvents = g_inventorApplication.ApplicationEvents
End Sub
Private Sub m_onDocumentChangeEvent_OnDocumentChange(ByVal DocumentObject As Inventor.Document,
ByVal BeforeOrAfter As EventTimingEnum,
ByVal ReasonsForChange As CommandTypesEnum,
ByVal Context As NameValueMap,
ByRef HandlingCode As HandlingCodeEnum) Handles m_onDocumentChangeEvent.OnDocumentChange
If BeforeOrAfter = EventTimingEnum.kAfter Then
MsgBox("OnActivateDocument " & DocumentObject.DisplayName)
End If
Label1.Text = "Inventor document name"
End Sub
End Class
Is it possible to change the label name when I change the the document"??
Solved! Go to Solution.
Solved by CattabianiI. Go to Solution.
Solved by CattabianiI. Go to Solution.
Have you debugged this code? Does it stop in the event handler?
OnDocumentChange fires when a document has a change, which means a parameter modification, a feature modification and so on.
Maybe what you need is OnActivateDocument?
Have you debugged this code? Does it stop in the event handler?
OnDocumentChange fires when a document has a change, which means a parameter modification, a feature modification and so on.
Maybe what you need is OnActivateDocument?
Thank you for the reply.
I did what you suggested but now I cant even debug the program. I get this error message at
OnDocumentChange
Do you know what i do wrong?
Thank you for the reply.
I did what you suggested but now I cant even debug the program. I get this error message at
OnDocumentChange
Do you know what i do wrong?
OnDocumentChange and OnActivateDocument have two different signatures (number and type of arguments of the event handler), check the sintax in the manual I linked in the previous message.
OnDocumentChange and OnActivateDocument have two different signatures (number and type of arguments of the event handler), check the sintax in the manual I linked in the previous message.
I can debug the program, but when I'm in the Form and I change files inside inventor it doesn't work. It doesn't trigger the code. What am I doing wrong? Or is this not the code for the job?
I can debug the program, but when I'm in the Form and I change files inside inventor it doesn't work. It doesn't trigger the code. What am I doing wrong? Or is this not the code for the job?
Who is calling ActiveEvents method? can you debug that method?
Changing files means switch the active document or make a modification on a document?
Who is calling ActiveEvents method? can you debug that method?
Changing files means switch the active document or make a modification on a document?
Yes, I got it to work.
Just need to call the ActiveEvents...
I need to know when it changes the document. then I get some properties from the part, assembly or drawing.
Thank you for helping!
Yes, I got it to work.
Just need to call the ActiveEvents...
I need to know when it changes the document. then I get some properties from the part, assembly or drawing.
Thank you for helping!
Got another question. The following code isn't working...
Public Sub ActiveEvents()
g_inventorApplication = Marshal.GetActiveObject("Inventor.Application")
DocumentObject = g_inventorApplication.ActiveDocument
m_onDocumentChangeEvent = g_inventorApplication.ApplicationEvents
m_appEvents = g_inventorApplication.ApplicationEvents
End Sub
Private Sub m_onDocumentChangeEvent_OnActivateDocument(ByVal DocumentObject As Inventor.Document,
ByVal BeforeOrAfter As EventTimingEnum,
ByVal Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_onDocumentChangeEvent.OnActivateDocument
If BeforeOrAfter = EventTimingEnum.kAfter Then
If _invApp.ActiveDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
If BackgroundWorker3.IsBusy <> True Then
BackgroundWorker3.RunWorkerAsync()
End If
End If
End If
End Sub
Private Sub BackgroundWorker3_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker3.DoWork
'some code
End Sub
Private Sub backgroundWorker3_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As RunWorkerCompletedEventArgs) Handles BackgroundWorker3.RunWorkerCompleted
Dim drawingdoc As DrawingDocument
drawingdoc = _invApp.ActiveDocument
Dim labeltext As String
labeltext = drawingdoc.DisplayName
'MsgBox(labeltext)
Label24.Text = labeltext
end sub
the part where it go's wrong is when i give Label24.text a new name. I get this error message.
Got another question. The following code isn't working...
Public Sub ActiveEvents()
g_inventorApplication = Marshal.GetActiveObject("Inventor.Application")
DocumentObject = g_inventorApplication.ActiveDocument
m_onDocumentChangeEvent = g_inventorApplication.ApplicationEvents
m_appEvents = g_inventorApplication.ApplicationEvents
End Sub
Private Sub m_onDocumentChangeEvent_OnActivateDocument(ByVal DocumentObject As Inventor.Document,
ByVal BeforeOrAfter As EventTimingEnum,
ByVal Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles m_onDocumentChangeEvent.OnActivateDocument
If BeforeOrAfter = EventTimingEnum.kAfter Then
If _invApp.ActiveDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
If BackgroundWorker3.IsBusy <> True Then
BackgroundWorker3.RunWorkerAsync()
End If
End If
End If
End Sub
Private Sub BackgroundWorker3_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker3.DoWork
'some code
End Sub
Private Sub backgroundWorker3_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As RunWorkerCompletedEventArgs) Handles BackgroundWorker3.RunWorkerCompleted
Dim drawingdoc As DrawingDocument
drawingdoc = _invApp.ActiveDocument
Dim labeltext As String
labeltext = drawingdoc.DisplayName
'MsgBox(labeltext)
Label24.Text = labeltext
end sub
the part where it go's wrong is when i give Label24.text a new name. I get this error message.
RunWorkerAsync in that event handler without await, updating somthing in the UI thread; this could be really painful: is it really necessary? The exception seems to talk about threads, right?
I think here is more about threads in .NET and the web has plenty of Q&A about this matter, than Inventor related things.
RunWorkerAsync in that event handler without await, updating somthing in the UI thread; this could be really painful: is it really necessary? The exception seems to talk about threads, right?
I think here is more about threads in .NET and the web has plenty of Q&A about this matter, than Inventor related things.
I fixed it with the
Control.CheckForIllegalCrossThreadCalls = False
code
I fixed it with the
Control.CheckForIllegalCrossThreadCalls = False
code
Can't find what you're looking for? Ask the community or share your knowledge.