In Inventor 2019, we have incorporated an experimental mechanism that allows you to use Visual Studio to debug your iLogic rules. It is not a seamless experience, but nevertheless is an effective technique. We are looking for feedback as to whether the quirks in the experience are tolerable, versus the benefits of being able to use an industrial-strength debugger.
To debug your iLogic rules:
- Prerequisite 1: Install Inventor 2019 or a later version (does not work in 2018 or earlier releases)
- Prerequisite 2: Install Microsoft Visual Studio 2017 or 2019 (Community, Professional or Enterprise edition. Not "Code"). The "Community" edition is a free download if you meet certain qualifications, available here: https://www.visualstudio.com/downloads/ Earlier versions of VS will probably work, too. We have not tested every version of every edition, but we expect that any recent version will be OK. When I tested the Community edition, I only installed the ".NET Desktop" subset. For more information about Visual Studio, try these links:
https://www.visualstudio.com/vs/community/ https://visualstudio.microsoft.com/license-terms/mlt031819/ https://www.visualstudio.com/vs/pricing/#tab-b8953f16f0b68f60f18 - Setup:
- Start Visual Studio ("VS").
- Create a new VS project using "Visual Basic Class Library (standard .NET Framework)". You don't have to do anything with this project, you just have to have one, so it's OK to accept all the defaults.
- Turn on all CLR Exceptions, as shown here:
- Disable the option shown below:
- Enable the option shown below:
To debug your rules:
- Open an Inventor file with iLogic rules.
- Start Visual Studio ("VS")
Open the VS project you created (or create a new one)(not necessary)- Attach VS to the Inventor process. This is easy in VS 2017 or 2019, a little trickier in earlier VS versions. Put "Inventor" in the search box to find the process. Use the "Attach to" option set to "Managed (v4.6, v4.5, v4.0) code" (automatic)
- Set breakpoints by one or more of these methods:
- Use this function in your rule: Break (as a single line of code in your rule). This is persistent (across sessions, like any code in your rule)
- Get an exception (error) in your rule-code. VS will automatically stop and give you the chance to inspect the state.
- Later, you can use additional VS breakpoints, by simply clicking on the line where you want to break, in the VB files in VS, once the files are loaded. These breakpoints are saved with the VS project, and can be used again in future sessions.
- Now go back to Inventor and run the rule. If the rule execution hits a breakpoint or gets any exception, then the code will stop in VS, and you can use all the VS tools to examine the current state. Note that Inventor itself is "hung" at this point; you cannot do anything else inside Inventor while you are at the breakpoint. When you're ready to go back to Inventor, click "Continue" (or press F5), and use Inventor normally after that.
- Tools you can use:
- Examine values of local variables
- If a variable is declared "as Object" (perhaps implicitly), use the "Dynamic view" to its properties
- Use "Watch" window to enter expressions, especially to see items of arrays/collections, e.g., myArray(6)
- Call stack
- Use "debug.print" in your rule to send text to the "output" window
- In addition, in 2019.1, you can also use the new iLogic "Logger" functions (does not require nor use VS).
- However, note that "the code" that you see in VS is not exactly your original code from your rule. It has been "processed" to support some special iLogic features. VS is actually using a temporary file that is "pure" Visual Basic. Fortunately, the differences are minor, including: "wrapper" code, conversion of unit-strings to expressions, extra "m_parameter" on parameter-names, etc.
- When you have found the problem, you have to use the Rule Editor to change the code of the rule. You cannot edit the temporary VB file directly in VS (think of it as read-only).
- By default, all rule code temporary files are stored in the folder "%Temp%\iLogic Rules"
Re-stating some of the known limitations:
- You have to install and run Visual Studio (VS).
- You have to start VS and "attach" it to the running Inventor process.
- Inventor is "hung" while in the breakpoint.
- The "code" that is displayed has some minor deviations from the rule as-written.
- You cannot edit your code in VS, you must go back to the Rule Editor.
We welcome your feedback on this experimental feature.
Differences between the code in the rule and the code shown in VS:
- "System code" – extra bits and pieces that iLogic provides for you. These lines are flagged with a comment, "**iLogic system**", and you can ignore them.
- "m_parameter_" – references to parameters will have this prefix
- Units ...
- Highlighting
Things to try to get used to it:
- Start with a simple rule that has both local variables ("dim xxx =thisDoc.path") and references to parameters in the document.
- Insert a "break" line in the rule.
- Run the rule; it should automatically stop in the debugger (VS)
- Use "F10" (Or click on "step over" icon) to step through. You may have to use it once just to get it "in".
- Look at the values of the variables in the "Locals" or "Auto" pane.
- Try to use Inventor while still in the debugger – you can't. Inventor is "hung" while it is stopped in the debugger.
- Note that the code you're seeing is not (really) editable. You will have to use the Rule Editor to make changes.
- Click "continue" (or press F5) to go back to Inventor.
- Change your rule: Remove the 'break' line, and add a deliberate error, e.g., refer to the -1'th element of an array, etc.
- Run the rule. It should automatically stop in VS.
- Look at the values
- Enter some tests in a Watch window.
- Click "continue" or "F5"
-Mike Deck