Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Request user interaction before save and close

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
miechh
1668 Views, 11 Replies

Request user interaction before save and close

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.


Product Design Suite 2024
Inventor 2024 (v 28.20.27200.0000), Vault Basic 2024
Fusion 360
HP Workstation Z4
Intel Xeon 3.4GHz
32GB RAM
Windows 10 Professional (64bit)
11 REPLIES 11
Message 2 of 12
cadull_rb
in reply to: miechh

You may be able to determine which command is causing the save event by checking the value of Application.CommandManager.ActiveCommand.

 

Regards,

cadull

Message 3 of 12
miechh
in reply to: miechh

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.


Product Design Suite 2024
Inventor 2024 (v 28.20.27200.0000), Vault Basic 2024
Fusion 360
HP Workstation Z4
Intel Xeon 3.4GHz
32GB RAM
Windows 10 Professional (64bit)
Message 4 of 12
cadull_rb
in reply to: miechh

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

Message 5 of 12
miechh
in reply to: miechh

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.


Product Design Suite 2024
Inventor 2024 (v 28.20.27200.0000), Vault Basic 2024
Fusion 360
HP Workstation Z4
Intel Xeon 3.4GHz
32GB RAM
Windows 10 Professional (64bit)
Message 6 of 12
xiaodong_liang
in reply to: miechh

Hi,

As I remember, there is no event to fire before [Save Changing] dialog pops out.

If you just need to store some info, instead of vote the [Save Changing], I think you could still use OnSaveDocument, or OnCloseDocument. for Yes, OnSaveDocument will fire, while No, OnCloseDocument will fire. So in these events, store your info.
Message 7 of 12
humbertogo
in reply to: miechh

You can use

 

OnCloseDocument application Events

 

If BeforeOrAfter = EventTimingEnum.kAfter of kBefore 

Message 8 of 12
miechh
in reply to: xiaodong_liang

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.


Product Design Suite 2024
Inventor 2024 (v 28.20.27200.0000), Vault Basic 2024
Fusion 360
HP Workstation Z4
Intel Xeon 3.4GHz
32GB RAM
Windows 10 Professional (64bit)
Message 9 of 12
xiaodong_liang
in reply to: miechh

Hi , sorry, I am not clear on the procedure. As what I know, when you check out a document, there should be a local copy which you edit with. After editing, you can check in or just save the local copy for future check in. But it looks you mean OnDocumentClose will fire when checki-in?
Message 10 of 12
miechh
in reply to: xiaodong_liang

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):

  1. Dialog appears asking to save, choices are yes, no or cancel
  2. Selecting yes
  3. OnSaveDocument, kBefore is triggered
  4. Inventor saves document
  5. OnSaveDocument, kAfter is triggered
  6. Dialog asking to check-in drawing, selecting yes
  7. Vaulting document
  8. After vaulting is complete, OnCloseDocument, kBefore is triggered
  9. OnDeactivateDocument, kBefore is triggered
  10. OnCloseDocument, kAfter is triggered
  11. OnTerminateDocument, kBefore is triggered
  12. OnTerminateDocument, kAfter is triggered

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:

 

  1. Close drawing document (which is 'dirty'), by upper-right cross, or via File --> Close
  2. Dialog asking user to fill-in some administrative fields (my add-in) and press OK
  3. Select yes to save the drawing (standard Inventor dialog)
  4. Select yes to check-in the drawing (standard Vault dialog)

 

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.


Product Design Suite 2024
Inventor 2024 (v 28.20.27200.0000), Vault Basic 2024
Fusion 360
HP Workstation Z4
Intel Xeon 3.4GHz
32GB RAM
Windows 10 Professional (64bit)
Message 11 of 12
adam.nagy
in reply to: miechh

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,



Adam Nagy
Autodesk Platform Services
Message 12 of 12
miechh
in reply to: adam.nagy

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.


Product Design Suite 2024
Inventor 2024 (v 28.20.27200.0000), Vault Basic 2024
Fusion 360
HP Workstation Z4
Intel Xeon 3.4GHz
32GB RAM
Windows 10 Professional (64bit)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report