Parsing iLogic of File with iLogic or Other Code

Parsing iLogic of File with iLogic or Other Code

Anonymous
Not applicable
957 Views
6 Replies
Message 1 of 7

Parsing iLogic of File with iLogic or Other Code

Anonymous
Not applicable

Hey All,

 

The company that I work for uses Autodesk Inventor iLogic extensively. I have been working on automating a number of information checks that can be run on models, but I would like to extend that to include iLogic problems (that don't trigger errors). To do so I want to be able to parse a iLogic rule like you would a text file so I can check the text. I am fine doing this in iLogic or in a external Python/C++ script. A previous engineer did something like this but I am not sure how, anyone have any ideas on how to access this data? I would prefer not to use a command capture script program.

0 Likes
Accepted solutions (1)
958 Views
6 Replies
Replies (6)
Message 2 of 7

johnsonshiue
Community Manager
Community Manager

Hi! Are you talking about the ability to debug or step through the iLogic code? I don't believe it is available. We do hear this request before. But, we don't have a solution yet.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 3 of 7

Anonymous
Not applicable

Hey Johnson,

 

I am thinking of a different thing, though I would love that too! What I am talking about is treating the iLogic rule as a text file. In the case of a external rule I could I can easily have VBA code (or python, etc) open it up as a text file. This lets me do things like update all instances of DRT to TCR (random example). In my case I would use this to check the code for best practices (this can be left abstract as then it is just general text code problem and not Inventor specific). The problem is that the iLogic rule on a part or assembly is not a separate file and so I cannot access it directly like that, but I need that style for my companies model structure (every part/asm has a large rule I need to check).

 

My question is how can I access the iLogic rules text? I know a previous engineer achieved this but I have yet to figure out how.

0 Likes
Message 4 of 7

johnsonshiue
Community Manager
Community Manager

Hi! It is doable. It is call external rules. Any iLogic rule can be saved as a text file. In iLogic browser panel -> click on External Rules -> select the text file. The rule will be driven by this external text file. Is this what you were looking after?

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 5 of 7

Anonymous
Not applicable

So it is close to what I want, but I need to be able to automate the saving out of the file then. Basically I need to be able to take a file that only has a ilogic rule in the ipt, and be able to access the text in the ilogic without any manual interaction. If there is a way that VBA can make that ilogic rule into a external rule and then convert back without me having to do the save out manually then that would achieve what I am trying to do. The script I am running will be doing this to a 30-40 parts at a time multiple times a week (not the same files), so I only can do it if fully automated.

0 Likes
Message 6 of 7

JelteDeJong
Mentor
Mentor
Accepted solution

Its possible to get the text of an iLogic rule using the iLogic addin. see this example.

 

dim iLogicAddin As ApplicationAddIn = Nothing
dim iLogicAutomation = Nothing
Try
   iLogicAddin = ThisApplication.ApplicationAddIns.ItemById({3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
Catch ex As Exception
   MsgBox("ilogic addin was not found")
End Try 
Try
   iLogicAutomation = iLogicAddin.Automation
Catch ex As Exception
   MsgBox("Unable to set variable iLogicAutomation.")
End Try

For Each rule In iLogicAutomation.Rules(ThisDoc.Document)
   MsgBox(rule.Name)
   MsgBox(rule.Text)
next

 

(I could not test this code. let me know if it does not work)

 

There is an other option if you dont want to use the iLogic addon. All iLogic rules are saved in the part as an attribute. you can try to read out the iLogic attributes. if you want to view attributes you can use the attribute helper.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 7 of 7

Anonymous
Not applicable

Hey Jelte,

 

Thanks for that information, it was very helpful! I ended up going with the attribute route and got this basic code to rule to get the text into a message box.

 

 

    ' Get the active document.  It can be any type of document.
    Dim oDoc As Document
    oDoc = ThisApplication.ActiveDocument
	
    ' Get the AttributeSets object from the selected entity.
    Dim attSets As AttributeSets
    attSets = oDoc.AttributeSets

    ' Check to see if it has the "SampleSet" attribute set.
    If attSets.NameIsUsed("iLogicRule_Name2") Then
        ' Get the attribute set.
        Dim attSet As AttributeSet
        attSet = attSets.Item("iLogicRule_Name2")

        ' Get the attribute on the set.
        Dim att As Inventor.Attribute
        att = attSet.Item("iLogicRuleText")
        MsgBox ("Attribute " & att.Name & " = " & att.Value)
    Else
        MsgBox ("The entity does not have the expected attribute set.")
    End If

 

 

From here I should be able to do everything else I was aiming for!

 

EDIT:

 

I actually switched to your code as it better tracks rule name. I corrected a couple things that was throwing errors

	Try
		iLogicAddin = ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
	Catch ex As Exception
		MsgBox("ilogic addin was not found")
	End Try 
	Try
		iLogicAutomation = iLogicAddin.Automation
	Catch ex As Exception
		MsgBox("Unable to set variable iLogicAutomation.")
	End Try
	
	For Each rule In iLogicAutomation.Rules(ThisDoc.Document)
		MsgBox(rule.Name)
		MsgBox(rule.Text)
	Next

 

 

0 Likes