Playing By the iLogic Rules

What is iLogic?

iLogic began as a third-party plug-in for Inventor that was purchased by Autodesk. Beginning with Autodesk Inventor® 2011, iLogic is included with the product.
iLogic provides a simple and easy way to add design intent to your parts, assemblies, and drawings.

Without realizing it, iLogic allows you to become a coding genius without having to learn much actual code at all!

What are iLogic Rules?

Autodesk Inventor’s iLogic programs are known as Rules. Just like Visual Basic for Applications (VBA), iLogic Rules can be saved within a document (part, assembly, or drawing) or as a separate file.

In this article we will discuss the benefits and pitfalls of both methods.

Internal and External Rules

iLogic Rules saved within a document are known as Internal Rules. iLogic Rules saved directly to disk are known as External Rules.
External Rules are saved as .iLogicVb files; however, you can also save Rules as a .VB file if you want to be able to open it up in Visual Studio or as a .TXT file if you want to be able to edit your Rule in Notepad.

Note: If you edit a Rule with an external editor you will need to use ‘Reload from File’ from the right-click menu in the iLogic Rule tree to bring the changes into Inventor.

Figure 1: Reload iLogic rule from file.

Local and Global Forms

With Inventor 2012, we now have the extra cool addition of Forms (i.e., dialog boxes) that we can add to our iLogic code.

Like Internal Rules, Forms are saved within a document. Like External Rules, Global Forms are saved out to disk.

Note: Forms have a great deal of functionality on their own. They don’t need to be hooked up to Rules to do their funky stuff.

When to use Internal Rules

Internal Rules are saved in the document. This is great if you are writing a specific, bespoke Rule that is only going to apply to one part.

For example, if you have a part that could be any length, but can’t exceed the maximum length in which the specified material is available, you could use an internal iLogic Rule to warn the user.

Here’s a good example of that situation by Jon Landeros:

The advantage is that the Rule is copied with the part and will always remain with the part, no matter where that part is used.

The disadvantage is that if you need to edit or correct the code, you will have to track down every copy of that part to perform the edits!

When to use External Rules

External Rules are saved on your local or network drive. External Rules are great if you need to code a tool or utility that is a little more complex or that you wish to apply to many documents.

One advantage in this case is that any bugs in your code can be ironed out in the source file and will automatically be applied every time they are called in a document.
Here’s a good example by Curtis Waguespack, showing how to use iLogic to automatically fill out the name and date in your drawing’s title block. View it here:

Tip: External rules are great for creating iLogic code ‘Modules’ that you can reuse for other tasks.

The only disadvantage here is that you will need to remember to send your iLogic file with the document if you want the iLogic Rule to be used elsewhere.

Creating External Rules

To create a new External Rule, right-click in the External tab of the Rule browser and choose Create Rule.

Figure 2: Create an External rule.

Note: Clicking Add Rule allows you to load in Rules that already exist.

Notice that you can save your Rule anywhere you like. You could save locally if your iLogic Rule is a work in progress, or save on the company server if you are ready to share your Rule with others.

iLogic will look for Rules in the following places:

  • The folder in which the current Inventor document is located.
  • The current Inventor Project Workspace folder.
  • The list of folders set in iLogic Configuration.

If you plan on sharing your Rules with others in your company, it is a good idea to add your company iLogic folder to the list of folders in the iLogic configuration setup.

To do this, go to: Tools > Options > iLogic Configuration

Click on the drop-down arrow at the bottom of the panel to get to the button.

Figure 3: Start iLogic configuration.

At the top of the ‘Advanced iLogic configuration’ dialog, you can add your own folders to the list of places that Inventor will search for iLogic code.

Note: There is no easy way to set the iLogic file path from within Inventor’s default or project options. Currently you need to set this manually on each machine that will use iLogic.

Figure 4: Advanced iLogic configuration.

The ‘iLogic Addin DLL directory’ is the place to put any DLLs that you might have created to support your Logic Rules.

Tip: Forget where you saved your External Rule or Global Form? Right-click on a Rule or Form and choose ‘Open containing folder’ to track down its location.

Calling External Rules

The simplest way to run an External Rule is to simply right-click on it in the rule browser and choose Run Rule.

External rules can be made to run using an event trigger such as ‘On Open’ or ‘On Save’. To do this, go to: Manage > iLogic > Event triggers. 

Figure 5: Event triggers.

Select the event trigger you wish to use, and click Select Rules to select the rules you wish to run.

Figure 6: Rules triggered by Events.

Note: The 2010 version of iLogic only allows you to trigger Internal Rules from Events.

Figure 7: Rules triggered by Events.

You can also run an External iLogic Rule from within another iLogic rule using: iLogicVb.RunRule "MyRule"

Applying a new Rule to an existing (i.e. pre iLogic) document isn’t easy. However, Jürgen Wagner brings us this great solution.

Jürgen has written a addin which runs a Rule called IPT for every IPT that is saved, a rule called IAM for every IAM that is saved, and so on. You can check it out here:

Notes on External Rules

External Rules do not run automatically in response to parameter changes. If you need this functionality, you will have to code it yourself. Check out ‘ModelingEventsSink.OnParameterChange Method’ in the developer help.

Unlike when you write an Internal Rule, your parameter names are not automatically available to use as variables. For example, the following Rule statement won’t work in an external Rule:

MyParam = MyOtherParam * 0.5

Instead, use the long-hand method to call out your parameter:

Parameter("MyParam") = Parameter("MyOtherParam") * 0.5

Adding Bling to External Rules

You can include an icon for your External Rule to display in the Rule Browser. To do this, create a 16 x 16 .bmp file with the same name as the Rule file and put it in the same folder as your Rule.

Best Practices for writing iLogic Rules

  • Keep it simple! Don’t try to do too much with one Rule.
  • Break up your Rules into modules that you can reuse in other projects.
  • Be consistent in your naming conventions, file locations, and methods.
  • Write lots of comments on your code. Remember that it may be you who has to work out what this program does in six months’ time.

I hope that this article has helped you to understand the differences between Internal and External Rules. I encourage you to get out there and take your iLogic code to the next level!

Paul Munford is a Joinery Drafter (a ‘Setter Out’) for Beck Interiors, a Museum interiors specialist contractor in the UK. Paul has been drafting with Autodesk products for seven years, before which he designed and built scenery for theatre, film and TV. In his spare time, Paul writes the CAD Setter Out Blog. You can get in touch via twitter @CadSetterOut, or

Appears in these Categories