Quick Tip: Run “Before Save” Rule Only Once in Assemblies

By Jelte de Jong

In some cases, you want to have a rule that is triggered by the “Before Save” event trigger. For example, to check if the iProperty “Part number” was set. Something like this;

If you do this, you may get unexpected or unwanted results when you save an assembly with lots of parts that are changed. You could end up with many message boxes. One for each part that gets saved in the assembly. You probably only need to check the part number of the file that you are trying to save.

You can solve this by checking if the active document is the same as the document that is running the rule. (in the example the active document would be the assembly. And the document that is running the rule would be the part document in the assembly). That would work like this;

 
 ' Add this to the start of your rule
 Dim activeDocName As String = ThisApplication.ActiveDocument.FullFileName
 Dim thisDocName As String = ThisDoc.Document.FullFileName
  
 If (activeDocName <> thisDocName) Then
     ' the script was not triggered by the active document
     Return
 End If 

About the Author:

Jelte de Jong works for a company that creates custom heat exchangers. He has used Inventor for over 10 years. Jelte has worked mostly as a mechanical engineer, but in recent years he has combined his hobby (programming) with his professional life. He now works as a software/mechanical engineer. His main task is supporting the drawing office by creating and maintaining configurable models and Inventor add-ins.

Find Jelte de Jong on Linkedin, the official Inventor Customization Forum, or the Inventor App Store

To find out more about becoming an Unofficial Guest Blogger, click here:


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s