Inventor Vb.Net "AddIn" dll - ApplicationEvents_OnSaveDocument Executing Twice???

Inventor Vb.Net "AddIn" dll - ApplicationEvents_OnSaveDocument Executing Twice???

isocam
Collaborator Collaborator
195 Views
3 Replies
Message 1 of 4

Inventor Vb.Net "AddIn" dll - ApplicationEvents_OnSaveDocument Executing Twice???

isocam
Collaborator
Collaborator

Can anybody help?

 

I have created a simple Vb.Net "AddIn" dll for Inventor that runs whenever the Inventor "SAVE" button is pressed.

 

For testing purposes only, this "AddIn" shows a message box saying "HELLO WORLD".

 

This is the Vb.Net code that I am using....

 

Private Sub ApplicationEvents_OnSaveDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles ApplicationEvents.OnSaveDocument

If BeforeOrAfter = EventTimingEnum.kAfter Then
MsgBox("HELLO WORLD")
End If
End Sub

 

When I press the Inventor "SAVE" button the above routing executes twice, eg the message box gets shown twice.

 

Is this a bug, if not, does anybody know how I can stop the sub routine from executing twice?

 

Many thanks in advance!

 

Darren

0 Likes
196 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor

Most events are triggerd twice. once before the document is "Saved" and once after the document is "saved"

This gives you the possibility to execute any action befor or after the save action. The event argument BeforeOrAfter As Inventor.EventTimingEnum will tell you if the code is triggered before or after the save is executed.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

Michael.Navara
Advisor
Advisor

I agree with @JelteDeJong , but you code looks like you handle this.

Another reason can be if you register this event handler multiple times. Rather then (Dim WithEvents + Handles) I use AddHandler and RemoveHandler statements. In this case you have better control over the events handling. Don't forgot to remove handler, when the add-in is deactivating. 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @isocam.  Another possibility here is...that is the application level version of that event, instead of the document level version of that event, so it is not document specific.  Which means, it will run for every document that gets saved.  And when you save an assembly, or save a drawing, those both have 'referenced documents' which may also get saved at the same time as the main assembly or drawing.  Every time you open an assembly or drawing, all the other documents that it references, either for its assembly components, or for the models shown within views, also get loaded into Inventor's session memory at that time.  And it might be possible that changes have been made to some of those referenced documents, or automatic updates happened to then as they were being loaded into memory.  That means that some of those referenced documents may be 'dirty' (changes since last save).  When that is the case, Inventor will try to save them when the parent level assembly or drawing gets saved.  That may be why you are seeing the message twice when you only saved one document.  Just one possibility.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)