The blog presents a series of the most frequently asked questions, in relation to IT and CAD support questions from SME’s. The blog offers step by step support to CAD and IT users based on the most commonly asked solutions.Learn more
iLogic - Tracing issues in my code?
We've all been there ...
We run an iLogic rule and something doesn't update correctly. We need to find whats going wrong and start to stick in message boxes all over the place which stop the configuration running as it hits each one (a real time consuming task if your code has any form of iteration in it). We change the model configuration and it doesn't update or seem to be taking a long time ... how can we work out what is wrong ..... there must be a better way to trace issues.
Working with many of our iLogic customers we have found that there is a real need to have tracing within our code to help diagnose issues. If you do a quick search online you will find a post from Autodesk that describes a method of doing this, however, this uses a program external to Inventor. I like to have everything in one place and only want to see traces from iLogic without having to think about it.
To help you, our developers have created an add in for Inventor to help show tracing within Inventor which is freely available. This add in works with Inventor 2017 and 2018 and is available for older releases as needed.
Please contact us and we can email you the installer.
What to do with it:
First of all install the add in and and fire up an Inventor model to automate. Within Inventor you will now have a new panel on the add-ins tab on your ribbon. This will allow you to show the trace window and to clear it.
Clicking on, show, will now give you a new panel that can be docked on your screen where the trace commands will be shown:
Now we have the window on it's time to start writing to it. This console can have text, parameter / property values outputting as a rule runs. Customers use it to see when values are updated as well as when rules are triggered. Knowing these things allows you to rapidly problem solve any iLogic code. Whenever you want your rule to write out to the window just type:
Trace.Writeline("<Your text here>")
So if I have a parameter called WIDTH that I want to see the value of in the tracing window, I would write: Trace.writeline("WIDTH: " & WIDTH). If that Width had a value of 5000 mm then I would expect to see the trace window showing WIDTH: 5000 mm
In general, tracing behaviors and requirements should be considered from the outset of any development design as the exact desired behavior will likely depend upon context, code structure and error handling strategy. It is therefore best to add tracing in as you go rather than it being considered as a retrospective addition.
Many of you will already have models that you want to have some tracing in. To help Symetri has created an iLogic rule which will add in a line to the top and bottom of each of your rules. These lines will then trace when each rule starts and stops.
To add these tracing lines to your rules rules, copy and paste the below into an external rule and run it ONCE in the component that you want to add tracing to (note that it will add it to rules inside child files as well):
Sub Main auto = iLogicVb.Automation Dim iLogicAuto As Object iLogicAuto = auto Dim doc As Document doc = ThisApplication.ActiveDocument Dim ruleName As String Dim rules As Object rules = iLogicAuto.rules(doc) LogStart = "console.WriteLine(TimeString & " & """" & " " & """" & "&" & """" LogStartEnd = " - Starts"")" LogEnd = "console.WriteLine(TimeString & " & """" & " " & """" & "&" & """" LogEndEnd = " - ENDS"")" For Each rule In rules ruleName = rule.Name Trace.WriteLine(doc.DisplayName & " " & ruleName) 'WRITES THE TIME AND SOME TEXT TO THE FILE ruleText = rule.Text RuleStart = LogStart & doc.DisplayName & " " & ruleName & LogStartEnd & vbCrLf & vbCrLf RuleEnd = LogEnd & doc.DisplayName & " " & ruleName & LogEndEnd If ruleText.contains(RuleStart) = True Then trace.WriteLine("Skipped: " & doc.DisplayName & " " & ruleName) Else If ruleText.contains("Sub Main()") Then ruleText = Replace(ruleText,"Sub Main()","Sub Main()" & vbCrLf & RuleStart & vbCrLf ,Count := 1) ruleText = Replace(ruleText,"End Sub",vbCrLf & RuleEnd & vbCrLf & "End Sub" & vbCrLf ,Count := 1) Else ruleText = RuleStart & ruleText & vbCrLf & RuleEnd End If rule.Text = ruleText End If Next 'Starts to go into all the sub assemblies to do the same Dim invDoc As Document For Each invDoc In doc.AllReferencedDocuments Dim invDocrules As Object invDocrules = iLogicAuto.rules(invDoc) Try If Not (rules Is Nothing) Then For Each rule In invDocrules Dim invDocruleName As String invDocruleName = rule.Name Dim invDocruleText As String Trace.WriteLine(invDoc.displayname & " " & ruleName) 'WRITES THE TIME AND SOME TEXT TO THE FILE ruleText = rule.Text RuleStart = LogStart & invDoc.displayname & " " & ruleName & LogStartEnd & vbCrLf & vbCrLf RuleEnd = LogEnd & invDoc.displayname & " " & ruleName & LogEndEnd If ruleText.contains(RuleStart) = True Then trace.WriteLine("Skipped: " & invDoc.displayname & " " & ruleName) Else If ruleText.contains("Sub Main()") Then ruleText = Replace(ruleText,"Sub Main()","Sub Main()" & vbCrLf & RuleStart & vbCrLf ,Count := 1) ruleText = Replace(ruleText,"End Sub",vbCrLf & RuleEnd & vbCrLf & "End Sub" & vbCrLf ,Count := 1) Else ruleText = RuleStart & ruleText & vbCrLf & RuleEnd End If rule.Text = ruleText End If Next End If Catch ex As exception End Try Next End Sub
When you start with iLogic it is common that users leave rules to run automatically leading to strange update issues ... when this tracing is run, users often find that several of there rules might unexpectedly run several times, not at all, or in the wrong order. With this tracing we can start to pinpoint the problem.
If you want to know more about Symetri's Design Automation Services or have an issue and need some advice please get in touch.
Are you ready to adopt a transition from general 2D design into 3D? This blog goes into depth about Factory Design Utilities and how they can assist in the designing of products and projects, as well as Global change an organisations Design environment. It also explains how AutoCAD offers their users the choice to design in 2D, 3D or Inventor.Learn more