- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
AddIn event on document change
Hi!
I'm writing an addin that works with iProperties of the active document or the selected document. But I can't find the right event to trigger my code.
What I have now is 2 events,
first when the user selects an item (in assembly) this works fine for me.
' Add event handler for user selected object event m_UserInputEvent = m_inventorApplication.CommandManager.UserInputEvents AddHandler m_UserInputEvent.OnSelect AddressOf OnDocumentChangeEvent
But I want also an event when the user changes document open or switches active document on the bottom with tabs.
' Add event handler for OnDocumentChange event. m_AppEvents = m_inventorApplication.ApplicationEvents AddHandler m_AppEvents.OnActivateDocument, AddressOf OnDocumentChangeEvent
This second event fires more than I like, on open document 2x and on other unwanted moments. What event can I use for this?
Please kudo if this post was helpfull
Please accept as solution if your problem was solved
Inventor 2014 SP2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
this is how I add event triggers to the standardAddInServer:
at the start of the namespace i add the line
Private WithEvents oAppEvents As ApplicationEvents
as shown:
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
'Application events object
Private WithEvents oAppEvents As ApplicationEvents
This means I can them select oAppEvents from the left dropdown above yor code window, and from the right one you have a full set of event triggers ready. to use.
I Can then choose OnActivateDocument and I get the empty sub as below:
Private Sub oAppEvents_OnActivateDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles oAppEvents.OnActivateDocument
End SubAs you might've guessed, any code in here will fire upon a docuement being made active, eg switching between two docs.
but this trigger, as with all triggers will fire twice, once before the event and once after it. this is why you're seeing it happen twice,
To prevent this you need to tell the sub when you want it to fire, either before or after the event like this:
Private Sub oAppEvents_OnActivateDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles oAppEvents.OnActivateDocument
'fire after document is made active
If BeforeOrAfter = EventTimingEnum.kAfter Then
End If
'fire before document is made active
If BeforeOrAfter = EventTimingEnum.kBefore Then
End If
End Sub
hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hello,
I have tried this exactly as in your example, but for some reason it does not fire the sub.
what could be the cause?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You trying to adress two different events to one sub?
OnDocumentChangeEvent
it will not work this way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@SutherNe Solution is almost comlete only one small thing that you need set oAppevents
best way to add it in addin activate method :
g_inventorApplication = addInSiteObject.Application
oAppevents= g_inventorApplication.ApplicationEvents()
dont forget to declare g_inventorApplication like:
Public g_inventorApplication As Inventor.Application
or use your own object for inventor...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report