Here are my Top Ten Inventor iLogic tricks. I have included some mentions of the Inventor API and SDK too, since they go hand-in-hand.
Forums, forums, forums
When working with Inventor iLogic, it is important to remember that for the most part, none of what you are likely to create will be “entirely new” code. There is a good chance that somebody on the Autodesk Forums will have either already used the methods available (within iLogic) to do what you want to do with them, or at the very least be able to offer pointers as to how to achieve your goal.
The Inventor API team are always on hand to aid with a specific question and the Expert Elite will occasionally chime in as well.
A good starting point is the Inventor customization forum:
In particular, the search function (circled above) is one of the best ways to get started. Always make sure to include iLogic in the search string.
One of the most useful (and often overlooked) repositories available to even a seasoned iLogic user is the Inventor SDK. Normally available here:
It comprises two installers:
This installer contains the following tools:
The titles of which should be self-explanatory. 😉
This installer contains the following tools:
It is worth noting however that without even an Express version of Visual Studio installed, you will receive the following error and be unable to proceed with the installation:
Event watcher sample
Assuming you did have Visual Studio installed; one gem in the Developer Tools -> Tools folder is the Event Watcher, a standalone app that is especially useful if you want to see what commands are firing within Inventor when using the Inventor UI.
I have previously used this tool to discover and subsequently intercept the “file close” and “file save” events for example.
Keep It Simple, Stupid.
When working in iLogic, it is very easy to end up with an enormous codebase; and whilst this may seem like “do as I say, not as I do” I have in the past created iLogic routines with 500+ lines of code. It is not something I would recommend to anyone starting out. The easiest way to keep things simple is to limit each method to an absolute maximum of 10 variables. I.e. objects you define yourself:
The above is a good example of a limited number of variables leading to easily maintained code.
Another tip is regarding named objects you create; sometimes in a large iLogic rule, you will find an error, which results in a useless dialogue from the Inventor UI. Often, this sort of error can be as simple as a typo caused by an overly complex object name. Turning “Option Explicit on” is one method to eliminate these errors before running the rule.
A quick way of debugging iLogic code is to place message boxes throughout the rule:
This gives a nice prompt within the Inventor UI that things are running as planned.
I do not recommend including them within a (potentially long running) loop, unless you like clicking the mouse waiting for said loop to finish that is.
Visual Studio Express is the minimum required to install the a fore-mentioned Developer Tools and is especially useful if you are serious about working with the Inventor API.
Among its many attributes are:
Autocompletes code and can suggest options as you type.
These function in a similar way to the message boxes we discussed earlier, but allow the developer to step through the code line by line.
These are both things that Inventor iLogic is sorely lacking, but which is an unlikely implementation unfortunately.
Option Explicit on
A trick I picked up because of this topic of mine is that although VB.NET and thus Inventor iLogic is happy for you to use the following statement:
oleReference = doc.ReferencedOLEFileDescriptors.Add(s, kOLEDocumentLinkObject)
You will see (as in the case above) strange results within the Inventor UI.
The correct method to use for the above scenario is thus:
oleReference = doc.ReferencedOLEFileDescriptors _ .Add(s, OLEDocumentTypeEnum.kOLEDocumentLinkObject)
Notice the addition of the Type Name Constant preceding the link Object above. To help detect these constants in code, you simply add “Option Explicit On” at the top of the iLogic Rule. This will Force explicit declaration of all variables in an Inventor iLogic rule.
Commenting code is often something that is either forgotten or over-used. For instance, when naming objects, there is no need to comment every variable, provided each uses a sensible name. For example:
“Dim selectedfile As String = String.Empty” Would not require a comment whereas:
“Dim a As String = String.Empty” Would require a comment to denote what ‘a’ means.
Granted, for a small piece of Inventor iLogic it may not be necessary to comment anything, but let us say for instance that you write a comment-free iLogic rule that works so well you do not need to update it for 6 months.
When you next attempt to edit this piece of code, the lack of comments will likely mean spending half a day or more getting to grips with what the code is doing.
Another trick that Visual Studio has up its sleeve (which would be useful in Inventor iLogic) is the ability to auto-expand any instance of three apostrophe characters preceding a method into a block of text resembling this:
Obviously, if you have installed a copy of Visual Studio, and you want to include this kind of commenting, you can copy the header that defines your method into a vb.net class open in Visual Studio, hit apostrophe three times on the line above and it will expand into the layout seen in the image above.
Built-in tools for user ease
For beginners, typing logic statements within iLogic is sometimes a difficult idea to get to grips with.
The iLogic “Edit rule” window does an okay job of highlighting the most-used of these:
There is also the Operators drop-down:
Clicking any of these dropdown items inserts them into the iLogic rule window.
Snippets are your friend
The Snippets available in the iLogic Rule Editor are (by me anyway) an underused addition to the iLogic toolset:
Snippets allow the user to create iLogic rules with minimal searching of the Inventor API documentation.
The snippets included by default allow for simple things like iProperty changes, feature suppression and mathematics through to more advanced topics like running other iLogic rules or even vanilla VB.NET code.
Custom snippets contain parts of actual rules, which you can place into your rules and use them without any modifications:
One of these snippets even allows you to make Inventor talk to the user.
Vaulted iLogic is Good iLogic
Lastly, I find an easy way of creating a repository of iLogic rules is to simply create a sub-folder in Vault and check the files in.
This way, any time you wish to make a change to the Rule in question, you first have to check the file out, and then check it back in when complete. This builds a revision history similar to that which you might see on www.github.com or other similar service.