First, let's briefly go over what iLogic is. iLogic is an Inventor add-in that allows you to create chunks of code called "Rules". You can create rules that are embedded in the Inventor files and also External Rules that you will need to store somewhere, such as on a network drive, or in your Inventor work space. The programming language used in iLogic is Visual Basic (VB). One of the biggest benefits of iLogic is the collection of snippets built into it that can be used to perform numerous tasks. Depending on what you are trying to accomplish, you could create a functioning iLogic rule that contains no VB code, and only uses the snippets.Now the Inventor API, or Application Programming Interface, is a collection of functions that are exposed by Inventor that allows another program to control it. Typically the API is used in an external program or an add-in but the functions can also be used within iLogic. I can already hear you asking, "If I can use both the iLogic snippets and the API within iLogic, it sounds like iLogic is the way to go?"
When you should use iLogic:
- If you are new to programming, you should definitely use iLogic. The reason for this is you can take advantage of the built in snippets, and the code is already bound to the active instance of Inventor and therefore any document that is open. With the API you need to manually bind your code to your instance of Inventor.
- You are trying to accomplish "simple" tasks with the code. Again, the snippets make it very easy to change parameter values, set iProperty values, change part material, etc.
- You are alright with the code "living" in the Inventor files. The only way to update the code in the files is by opening each file and updating manually.
When you should use the Inventor API:
- You are an experienced programmer and are familiar with using API's.
- You are creating an external application or add-in. You are able to tell iLogic rules to run using the API but I have noticed performance issues when I have tried doing so.
- The tasks you are trying to accomplish are more complex and would benefit from reusing chunks of code often. This point is what caused me to switch from using iLogic to primarily using the Inventor API in an external application.
- Your programming language of choice is not VB. You can use any .NET language such as VB, C#, F#, etc. with the Inventor API.
My Inventor Programming Progression
The first time I used the Inventor API I was creating a rule to make a sheet list in my drawing. This eventually became the Sheet List Add-in I have available on the Autodesk App store, which was originally written in VB.net but has since been re-written in C#.
I switched to primarily using the API in an external application when I started having a lot of reusable code. I originally had the code in multiple Inventor files but it quickly became impossible to maintain, having to remember all the different files.
Obviously there are no hard set rules for when one should be used over the other. You can create very complex iLogic rules and it will work. Should it be done? Probably not. Have I done it? Yes I have. The same goes with the API. You can do some very simple things with it and it will work perfectly fine. It just will be more work than just using an iLogic rule.
One last thing to keep in mind. When creating iLogic rules that contain loops, make sure you ALWAYS save the file before testing the rule. There is no way to stop a rule from running and you can get caught in an infinite loop. The only way to stop it is by forcing Inventor to shut down, which if you have not saved your file, you will lose your work. Another way around this is by building in escapes into the loops, such as making it stop after 1000 iterations. Just a little advice from someone who has lost many lines of code because of this.