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

Blog | Autodesk Forum | LinkedIn | Autodesk App Store

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: