The latest update for Autodesk Inventor gave us the iLogic Log. If you either write iLogic rules or have to debug iLogic rules, it's worth your time to continue reading and check out this new tool. It really goes without saying that if you do the former, then you're going to be doing the latter as well. Also, if you've always wanted to be a logger, then continue on!
The iLogic Log gives you a better understanding of what is going on while your iLogic rules are running. Have you ever needed to know what value a variable had at a particular point or wanted to know which block you were getting into inside of a conditional statement? The Log will let you to do that in an easy manner. Previously you may have thrown this type of information out to a message box that had to be acknowledged before the rule would continue.
The iLogic Log allows you to print data in the Log panel by using the new Logger function. The context for the function is Logger.LogLevel("your message"). There are multiple levels that you can use in the LogLevel placeholder. They are (in order): Trace, Debug, Info, Warn, Error, Fatal, and None. The active Log Level determines what log message get printed to the Log. Only those functions that use a level at or below the active Log Level will be displayed.
For example: I would like to know the value of the Overall_Length parameter at a certain point in one of my rules. My active Log Level is Info. This means I'll see any Logger functions that use Info, Warn, Error, or Fatal.
I've created a rule in my part called Initial_Rule. I've entered the following lines into this iLogic rule:
Logger.Info("Overall_Length: " & Overall_Length)
When the rule runs, I'll see the following:
To turn on the Logger panel, either use the Show Tabs icon on the Model Browser or the User Interface flyout in the Windows Panel of the View Tab of the Ribbon.
You can set your active Log Level through the Advanced iLogic Configuration dialog box. You can also select the active Log Level through a drop down that appears when you first open the iLogic Log Panel but I have yet to figure out how to get that menu back!
You can also use the new iLogic Log to trace when your rules fire. Setting the active Log Level to Trace will cause the Log panel to also show when you are entering and exiting a rule.
In my example scenario, I've created an additional rule called Secondary_Rule and entered the following lines into it:
Logger.Info("Secondary Rule ran")
When I run the Initial_Rule, I get the following ouput in the Log panel:
INFO| 1: >>---------------------------
TRACE|Entering rule: Initial_Rule (in iLogic Logger.ipt)
TRACE|Entering rule: Secondary_Rule (in iLogic Logger.ipt)
INFO|Secondary Rule ran
TRACE|Exiting rule: Secondary_Rule (in iLogic Logger.ipt)
TRACE|Exiting rule: Initial_Rule (in iLogic Logger.ipt)
I've been using DebugView (download here) for years to accomplish this same thing. If you're not on Inventor 2019.1, I'm afraid you won't be able to use the new iLogic Log. In that case, I suggest looking into DebugView. Click here to read an older blog post about DebugView.
Some of the benefits the iLogic Log has over DebugView:
- Internal to the program so there's no need to download something else
- No need to use a filter to limit what Logger sees as is needed in DebugView
- Built in Trace (although I always put lines at the front and back ends of my rules to emulate this)
- Log will capture your log data even if it isn't open when the rules run
Some of the benefits DebugView has over the iLogic Log:
- Can change the font size
- Can emphasis lines using the Highlight controls
- Can set the window to Always On Top
As with DebugView, there's really no need to remove the Logger function lines from your code. You can adjust the active Log Level to something higher than the level you've specified in your code but I've found it just as easy to leave it all there and ignore what I don't want to see.
I hope you can imagine how helpful this is! If you have any questions, be sure to post in the comments below and as always, Happy Coding!
*** UPDATE 9-20-2018 ***
You can change the font size in the iLogic Log. You can use CTRL+PLUS and CTRL+MINUS to zoom in and out after giving focus to the iLogic Log. You can also use CTRL+F and a zoom indicator will show up at the bottom of the iLogic Log panel. Big thanks to Mike Deck @ Autodesk for pointing that out!