After days of laborious work to create yourself the golden iLogic rule that your company cannot live without, the realization suddenly strikes that your golden rule will only work on newly created files.
How can you retrofit an iLogic rule to already existing files?
In iLogic, there is not such a thing like "automacros" such as in VBA macros.
How do you avoid having to paste your iLogic code manually in each and every file?
External rule anyone?
A piece to the solution of this puzzle is to use an external rule.
An external rule has one big advantage over a local rule.
It can be modified in a single central location while still affecting all files that call that external rule.
Calling an external rule in iLogic is very simple:
iLogicVb.RunExternalRule("externalrule.txt")
To focus attention, let's do something very basic in the external rule like bringing up a message box that displays the filename.
The rule in externalrule.txt to accomplish this, would be
MessageBox.Show( "File name of active document is " + Chr(13) + ThisDoc.PathAndFileName(True), "File name" )
But how can you get this one-liner systematically included in existing files?
API coming to the rescue
You can achieve this by using the AddRule command from the iLogic API as documented in the file called "Autodesk.iLogic.Interfaces.xml".
This file is located in the Inventor bin folder if you like to dive in for more details.
To put it all together, I created a VBA ivb project and an external rule. Both files are all you need to make it work and can be downloaded here.
Here is the procedure to use the files. It is important that you follow all these steps without skipping any.
1) First unzip the ivb and txt files to any folder. Example: C:\Shared\myivbprojects
2) In Inventor Tools > Options > iLogic configuration and add the name of your folder to the external rule directory paths.
Note : this command sits in the expanded panel by default, so it is rather difficult to find.
Figure 1: Adding location of external rules
3) Load the ivb project in the VBA editor via File > Load project ...
4) Run the macro initialize_iLogic_rule() in module Start_stop
5) Create a new Inventor file or open an existing file (if you want to treat multiple files you can also drag and drop files from Windows Explorer to Inventor)
6) An iLogic rule called "Myrule1" will be automatically created (if you run the rule you will see that it will try to display the filename)
7) Do not forget to turn off the automatic rule creation process if you no longer need it. You can do so by running the macro called stop_initialize_iLogic_rule() in module Start_stop.
Step 7 is really important if you want to stop adding rules automatically.
Extrapolation to more rules
Above code is dealing with a single external rule. What if you want to add multiple rules in one operation?
For example if you want to add a second rule, you will have to change just a single line of code and make sure that the extra string you provide matches the external file name Myrule2.txt etc:
To create two rules simultaneously, modify this line
listofrules = Array("Myrule1")
By adding an extra string
listofrules = Array("Myrule1", "Myrule2")
Make sure that the external rules with corresponding names exist:
Myrule1.txt , Myrule2.txt , etc
Now if someone can find the trick to automatically set triggers to run rules then we would have a complete automated solution … Anyone out there?
Have fun
Bob



Subscribe
iLogic run on save add in: http://inventorfaq.blogspot.com/2010/11/ilogic-regel-automatisch-beim-speichern.html
english: http://inventortrenches.blogspot.com/2011/08/built-for-speed-running-ilogic-rules.html
Posted by: Jürgen Wagner | 10/25/2011 at 07:54 AM
Thanks Jurgen!
I was not aware of Curtis Waguespack's utility to run iLogic rules on save. So everyone: if you want to run external rules in an automatic fashion or when certain conditions are met, read Curtis' article at
http://inventortrenches.blogspot.com/2011/08/built-for-speed-running-ilogic-rules.html
Bob
Posted by: Bob | 10/25/2011 at 08:25 AM
It's my tool, Curtis "only" wrote about it ;)
Posted by: Jürgen Wagner | 10/25/2011 at 11:43 PM
Great tips today too
Johan
Posted by: Johan | 10/26/2011 at 02:48 AM
Entschuldigung Juergen:-)
I completely missed that part in Curtis' post where he referred to you as being the original author. You're the man.
Bob
Posted by: Bob | 10/26/2011 at 10:30 AM
This helps me so much! ilogic!!!!
Posted by: Short Sale Portland | 11/01/2011 at 12:30 AM
Depending on your needs an add-in can be the better solution because it can be tied to the Application events (ie. On Save) without having to "link" any code to files.
Posted by: Ryan Small | 11/02/2011 at 08:17 PM
Agreed. But this is not within reach of the "average" user. It would be a topic more suited for Brian Ekin's blog. BTW he wrote about it at http://modthemachine.typepad.com/my_weblog/2010/01/how-to-write-an-inventor-add-in.html.
For reader's of our blog that are interested in exploring add-ins, I would refer them to this tutorial http://forums.autodesk.com/t5/Autodesk-Inventor/Check-out-the-self-paced-guide-My-First-Plug-in/td-p/3115624
But anyway thanks for mentioning it.
Bob
Posted by: Bob | 11/03/2011 at 09:12 AM
"Now if someone can find the trick to automatically set triggers to run rules then we would have a complete automated solution … Anyone out there?"
I have figured out a way to do that and have made a little program that will let you import / edit a rule, apply that rule (inject it) to a list of parts (of your desire), and set up the Inventor Event Triggers.
Once I do some more bug testing and gather my documents, I will throw it up on github and here, so that you can update this with event trigger stuffs.
Posted by: MegaJerk | 01/30/2012 at 02:56 PM
Great! Looking forward to your solution for auto-triggering :-)
Bob
Posted by: Bob Van der Donck | 01/31/2012 at 09:23 AM