I'm developing an add-in for Inventor which will be triggered when a drawingdocument is being closed. So far I learned how the OnDocumentSave-event is working and that I can program actions in response to this event and the OnDeactivateDocument, OnCloseDocument and OnTerminateDocument events. The goal of the add-in is to have the user fill in a form only when he/she closes the drawing document by selecting File --> Close, or via the cross in the upper right corner of the document-window. The data filled in on the form should then be saved to the iProperties of the drawingdocument, before the drawingdocument is closed definitely.
The problem is that when the user clicks on the cross to close the document, or via File --> Close, he will be asked whether to save the document or not (standard "Yes"/"No"/"Cancel"-dialogbox of Inventor). Until then, no event is triggered yet. When the user chooses to save, the OnDocumentSave event is fired. At first I put my code in this event, under the "kBefore" timing. It works. But this event is always triggered (quicksave-button), also when the user doesn't close the drawingdocument. The actual OnCloseDocument, OnDeactivateDocument and OnTerminateDocument-events are all being triggered after the save-action.
How can I find out if the drawing is being closed, before the actual save-action of the drawingdocument is started? Help is greatly appreciated.
Solved! Go to Solution.
Solved by adam.nagy. Go to Solution.
You may be able to determine which command is causing the save event by checking the value of Application.CommandManager.ActiveCommand.
Regards,
cadull
Hello cadull_rb,
Thanks for your reply. Could you please describe in some more detail how I should do this? Trying to read the Application.CommandManager.ActiveCommand property results in an error. At first I was trying with a Debug.Print to determine the value of that property, but that doesn't even seem to work. Guess I'm missing something.
I can confirm that calling Application.CommandManager.ActiveCommand during the ApplicationEvents.OnSaveDocument event generates an exception. I tried tracking the active command with UserInputEvents.OnActivateCommand, but pressing the save button does not generate this event. Using UserInputEvents.OnStartCommand was a little more successful, but the CommandIDEnum value when saving is 2140 which has been omitted from the enum and the documentation. This may be suitable; otherwise I'm out of ideas.
Regards,
cadull
Hello Cadull,
Thanks again for your reply. I'll have a try with the ideas you gave me and let you know the results. It's not really a problem that the UserInputEvents.OnActivateCommand event is not triggered by pressing the save-button; my application should be triggered by closing the document before the actual save-action is run.
You can use
OnCloseDocument application Events
If BeforeOrAfter = EventTimingEnum.kAfter of kBefore
This solution is acceptable for me. I was affraid that when I put a Document.Save() action in the OnCloseDocument event, the .OnSaveDocument event would be triggered over and over again. I put my code in the OnCloseDocument event and it works well if it isn't a Vault-document.
The next problem occurs:
When it's a Vault-document, the check-in procedure will fire before the OnDocumentClose-event, so when you put the Document.Save() command in this event, Inventor will ask you where to save your document after it's been checked in into the Vault, which is undesirable.
To find out what the sequence of events is when closing a document, I programmed all the events to display a messagebox with the event that was triggered at that moment. The order of events is:
user closes checked-out vault-document, which is 'dirty' (has changes but hasn't been saved yet):
So putting code to save something to the document after the OnCloseDocument kBefore-trigger doesn't work, the document has already been checked in into the vault at that time.
My wish is the following:
When just (quick)saving the drawing, the user shouldn't be asked to fill in the administrative fields, so only when actually closing the drawing.
Hope this is clear.
Hi,
So basically when the OnSaveDocument event is called you would like to be able to tell if this is occurring as a result of closing the document, right?
Unfortunately, this looks tricky. As you've found no close related event is fired before OnSaveDocument and
The only thing I can think of now is using some Win 32 hooks to see that e.g. the close button (x) got clicked on the document view.
But thinking more about it, I don't think it would work, because the user could still decide to Save the document and then click close, in which case there would not be another save fired as a result of the close and the file is already checked into Vault.
So I think you would just have to handle each save event, no matter why it is fired. And if the user already provided the necessary info then you would not have to ask again.
Cheers,
Thanks Adam. I've taken a lot of time to find out if there's a solution to this, but as you wrote yourself, it won't be watertight. So I accept the solution of catching every save-event. It's a rather blunt method, but it'll suffice.
Can't find what you're looking for? Ask the community or share your knowledge.