Interrupt 'Save Document' from iLogic rule started with Event Trigger

Interrupt 'Save Document' from iLogic rule started with Event Trigger

checkcheck_master
Advocate Advocate
832 Views
3 Replies
Message 1 of 4

Interrupt 'Save Document' from iLogic rule started with Event Trigger

checkcheck_master
Advocate
Advocate

Is it possible to stop a Save Document action from an iLogic rule who is fired with an Event Triger Before Save Document?

When reuse a drawing and do a 'Replace Model Reference' there is a chance to forgot to change to the new drawing name.

Therefore I wrote a iLogic rule that is comparing the model file name with the drawing file name and gives a warning when there is a difference between.

I would like to give the user YES/NO buttons and when go for NO to stop the Save Document action.

Is that possible while using the regular ctrl-S and save button?

In other words, can the iLogic rule intervene in the running process?

' Check_Drawing_Reference
' Get model doc and path
Try
	'Find the first model ref in the drawing
	Dim iDoc As Document = ThisApplication.ActiveDocument
	oPathIdoc = iDoc.FullFileName
	oDoc = ThisDrawing.ModelDocument
	oPath = oDoc.FullFileName	
Catch
	MessageBox.Show("Could not get model reference.", "iLogic")
	
	Return
End Try

strText = "Drawing filename is not the same as model filename!" & vbNewLine & vbNewLine & _
          "Model:" & vbNewLine & Left(oPath, Len(oPath) -4) & vbNewLine & vbNewLine & _
		  "Drawing:" & vbNewLine & Left(oPathIdoc, Len(oPathIdoc) -4)

' Compare Model doc and Drawing doc
If Left(oPath, Len(oPath)-4) <> Left(oPathIdoc, Len(oPathIdoc)-4) Then

	MessageBox.Show(strText, "WARNING!",MessageBoxButtons.OK, MessageBoxIcon.Warning)
	
End If

 

 

 

 

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

Ralf_Krieg
Advisor
Advisor

Hello

 

You can use a custom event handler to do this. In this post MjDeck described it for the OnParameterChange Event. For the OnDocumentSave Event it would be similar. You can run the rule enabling the custom handler on open a document. If the shared variable signaling the handler already exist, nothing happen. Otherwise it will be added.

If you change anything within the handler, remove it first, make your changes and add it again or restart Inventor.

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 4

Bellmer-CAD-Admin
Enthusiast
Enthusiast

I have the same Question as checkcheck_master and from ChatGPT i found:

 

"iLogic in Autodesk Inventor doesn't provide a direct method to interrupt a save command once it has been initiated. iLogic operates within the constraints of the Autodesk Inventor environment, and certain system-level operations like saving files cannot be directly interrupted programmatically once they are initiated."

 

We are using Inventor 2023.4 and would like to check files for some common user mistakes before saving. So we use the "before saving trigger". If there are some of these faults, the save command should be interrupted. (Because we want to select parts with ilogic in an assembly to show the user which files need to be changed - a save will clear the selection).

 

 


0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @Bellmer-CAD-Admin.  The question was already answered to some degree.  Yes, it should be possible to stop a document from being saved, but maybe just not the way you had in mind.  When you are just using the Event Triggers dialog to trigger your rule to run, which is supposed to check something about the document before save, then no, that would most likely not work as planned, because once the rule has finished, the document will continue to be saved, no matter what you do.  If you must truly interrupt the save process, and optionally stop it from happening, then you must use a custom event handler code routine (like what is common to use in an Inventor add-in), instead of using the iLogic Event Triggers dialog.  The iLogic Event Triggers dialog does not give you the level of control you need to cancel an event before it happens, but a custom event handler code does.

 

@Ralf_Krieg provided a link to a similar case in another forum post which was using a custom event handler code, and also provided a couple of similar codes in the two text files attached to his response.  When using a custom event handler code, there are two stages to almost all events (before & after), allowing us the ability to check things out before the actual action takes place, and it also sometimes gives us the ability to cancel the actual action from taking place, but not always.  In this case, this event is cancelable.  There are actually two different possible events, with different 'scopes' that we can monitor with a custom event handler code (ApplicationEvents.OnSaveDocument Or DocumentEvents.OnSave).  To explain the difference in scope...the one within the ApplicationEvents will catch every document save event for all documents while Inventor is running, while the one within the DocumentEvents will only catch that event when it happens to the one specific document that the DocumentEvents was sourced from.  The two very similar events do not act exactly the same though, and if you only want to monitor one specific document, then I would suggest using the one from DocumentEvents, because it is much easier to manage, and will dispose of itself when the document closes.  Both events are cancelable, but the application level one reacts a second time to indicate that the event was canceled (aborted), but the document level one does not react a second time after being canceled.

 

If you 'need' to be able to cancel the save event, then it would probably be best to start the custom event handler running either when the new document is created, or when it is opened, then it will remain running in the background, 'listening' for then you attempt to save that document.  And when that happens, it will automatically catch that event in the 'kBefore' timing stage, check some things, then either allow the save to continue, or abort the action before it happens.  Not using the Event Triggers dialog's Before Save event.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes