i assume that you checked that the custom addon is also triggerd on the before timing event. I did have some ideas but when i recreated the situation all my ideas failed. except for your own sugestion. throwing an exeption. see code below.
Dim docEvents As DocumentEvents
Private appEvents As ApplicationEvents
Sub Main()
Dim doc As Document = ThisDoc.Document
appEvents = ThisApplication.ApplicationEvents
AddHandler appEvents.OnSaveDocument, AddressOf OnSaveEventCadacAddin
AddHandler appEvents.OnSaveDocument, AddressOf OnSaveEventCustomAddin
While True
Thread.Sleep(500)
End While
End Sub
Private Sub OnSaveEventCustomAddin(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
MsgBox("Custom save action: " & BeforeOrAfter.ToString())
End Sub
Private Sub OnSaveEventCadacAddin(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
HandlingCode = HandlingCodeEnum.kEventCanceled
MsgBox("Cadac save action: " & BeforeOrAfter.ToString())
Throw New Exception()
End Sub
This will stop the custom event from happening. But will only work if the Cadac event/addon is registered before the Custom event/addon is registered. To test this with addons you could try the following.
Manually unload the custom addon (probaly you need to restart Inventor) then load your addon first. After that reload the custom addon.
Now you can try to throw a exception in your save event function. If that stops the custom addon then you have a starting point. In that case you could always unload the custom addon when inventor closes and make your Cadac addon load the custom addon.
Any way if you manage to get it to work this way. I dont think it would be very stable. (for eaxample what happens if inventor crashes and the custom addon is not unloaded and is loaded before your addon on the next startup.) therefore this is far from a great solution.
If this is not good enough for you (i would not blame you) then maybe it is possible to undo the things that the custom addon does. For example
- if the custom addon write some values to the iProperties you could save the original values on the userInputEvents.OnActivateCommand (AppFileSaveCmd, ..... ) and writ them back on the cancel event.
- if some model changes are made in 1 transaction you could try to run the undo command ThisApplication.TransactionManager.UndoTransaction()
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.

Blog: hjalte.nl - github.com