iLogic Rules - External vs. Internal

iLogic Rules - External vs. Internal

karthur1
Mentor Mentor
1,307 Views
5 Replies
Message 1 of 6

iLogic Rules - External vs. Internal

karthur1
Mentor
Mentor

I wrote a simple iLogic rule that would write to a Custom iproperty based on the thickness of a sheetmetal part.  I have this rule working like a champ and have it embedded in my part (saved locally).  Now that I have it working, I decided rather than embedding it in the part, I would store it as an external rule.  That way if later I run into something that I have not tested I can fix it in one place.

 

What I have found is that with the rule as an external rule, it does not work and I cant figure out what the trouble is.

 

I have attached the part (with the embedded rule) and the external rule.  The two rules are identical. This rule does one thing, it writes to a custom iprop called "Gauge "  depending on what it finds for the material thickness.  For example, if the thickness is 0.1046in, then "Gauge" = 12.  If the rule does not find a match, then "Gauge" =N/A. 

 

1. If I use the local rule, then as soon as I change the material style, the correct value is stored in the "Gauge".  I am not sure why the internal rule is ran immediately, but it is.  There is no trigger set to fire this rule upon parameter change. I just thought that rules either had to be ran manually or set to fire with a trigger.

2. If I disable this local rule, and set a trigger for the External rule "Set Gauge Value_EXT" to fire on parameter change, I would expect the "Gage" value to be set to the correct value.  No matter what I do here, it keeps giving me the "N/A", like it cant find a match for the thickness.

 

Any help would be greatly appreciated.

 

Thanks,

Kirk

Inventor 2018.3.4

 

0 Likes
1,308 Views
5 Replies
Replies (5)
Message 2 of 6

AdamAG99T
Advocate
Advocate

I'm not sure exactly how you're getting the value in Thickness in the code you posted, from my understanding you need to use Parameter("Thickness") to get the value instead of just using Thickness in the ilogic. Changing to this might help you. I would also recommend adding a simple messagebox somewhere before the set of If statements displaying the value of Thickness to help troubleshoot temporarily, so you can tell if the issue is the value not being saved properly or something else. 

0 Likes
Message 3 of 6

Anonymous
Not applicable

On external rules you have to refer to things more formally (for lack of a better word). I recently made a bunch of external ilogic files from internal ones and ran into this.

 

In the attached code, the commented out section at top was the internal version, the lower version the external version:

 

'If SheetMetalLength > SheetMetalWidth Then
'	PL_LENGTH=SheetMetalLength
'	WIDTH = SheetMetalWidth
'	Else
'	PL_LENGTH=SheetMetalWidth
'	WIDTH = SheetMetalLength
'End If

If Parameter("SheetMetalLength") > Parameter("SheetMetalWidth") Then
	Parameter("PL_LENGTH")=Parameter("SheetMetalLength")
	Parameter("WIDTH") = Parameter("SheetMetalWidth")
	Else
	Parameter("PL_LENGTH")=Parameter("SheetMetalWidth")
	Parameter("WIDTH") = Parameter("SheetMetalLength")
End If
Message 4 of 6

Sergio.D.Suárez
Mentor
Mentor

Hi, The problem is when you take the variable "thickness".
Notice that in the internal rule every occurrence of the string thickness has a bluish color, this means that implicitly it is defined as the thickness parameter of your document.

Sin título.jpg
On the other hand, when you create the external rule, the appearance of each string is shown in reddish color, that is, it is not related to any internal parameter of the file where it is executed.

2.jpg

To solve this, in my case I defined the variable thickness accessing the document, but be careful ... you have to observe what is the default unit of inventor and what value it returns for this. Since in my case it is "mm", put a multiplication factor to correct the value I need. For this reason, put a text box to see if the value is correct, once the property is adjusted with the appropriate factor, the text box is deleted and the rule should work properly.
There is another method to specify the type of unit of the variable, but I prefer not to complicate the thing so much.
I hope I have been clear and that you can solve your problem. regards

 

'This rule is used in Sheetmetal parts.  When the thickness of the part
'is selected from the list, this will automatically change the gauge number
'that is used in the part description.  (Kirk Arthur, June 2019)

'set the value initially to "n/a", then if no match if found
' this is what is shown for the parameter.

iProperties.Value("Custom", "Gauge") = "n/a "

Dim Thickness As Double = ThisDoc.Document.componentdefinition.Parameters("Thickness").Value * 10 / 25.4

MessageBox.Show(Thickness)

'Sets Custom parameter for 6 Ga.
If Thickness = 0.1943 in Then
	iProperties.Value("Custom", "Gauge") = "6"
End If

'Sets Custom parameter for 7 Ga.
If Thickness = 0.1793 in Then
	iProperties.Value("Custom", "Gauge") = "7"
End If

'Sets Custom parameter for 8 Ga.
If Thickness = 0.1644 in Then
	iProperties.Value("Custom", "Gauge") = "8"
End If

'Sets Custom parameter for 9 Ga.
If Thickness = 0.1495 in Then
	iProperties.Value("Custom", "Gauge") = "9"
End If

'Sets Custom parameter for 10 Ga.
If Thickness = 0.1345 in Then
	iProperties.Value("Custom", "Gauge") = "10"
End If

'Sets Custom parameter for 11 Ga.
If Thickness = 0.1196 in Then
	iProperties.Value("Custom", "Gauge") = "11"
End If

'Sets Custom parameter for 12 Ga.
If Thickness = 0.1046 in Then
	iProperties.Value("Custom", "Gauge") = "12"
End If

'Sets Custom parameter for 14 Ga.
If Thickness = 0.0747 in Then
	iProperties.Value("Custom", "Gauge") = "14"
End If

'Sets Custom parameter for 16 Ga.
If Thickness = 0.0598 in Then
	iProperties.Value("Custom", "Gauge") = "16"
End If

'Sets Custom parameter for 18 Ga.
If Thickness = 0.0478 in Then
	iProperties.Value("Custom", "Gauge") = "18"
End If

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 6

karthur1
Mentor
Mentor

Sergio,

Thanks for the help.  I was missing the object "ThisDoc.Document.componentdefinition.Parameters("Thickness").Value".  I did not know exactly how to access the information that was in the model.

 

When I run the rule that you made, it works great the first time, but when I change the material to a different thickness, it puts "N/A" in the custom property, even when the thickness matches one of the "if" statements.  The dialog shows that it finds the correct thickness value.  If I delete the custom property "Gauge" and then run the rule it works. 

Maybe it needs to have something to delete the custom property "Gauge", just now sure why it will not change it correctly.

 

Thanks

Kirk

0 Likes
Message 6 of 6

Sergio.D.Suárez
Mentor
Mentor

Sorry for the delay in answering, you're right. It produces an error because in the background the default unit "cm" was never changed, so when comparing it does not give equality. The correct way would be to change the unit, I thought it would not be necessary but I'm wrong.
Here you have the code with the unit change.
I've tried it and apparently it works. I hope it is useful for you. regards

 

'This rule is used in Sheetmetal parts.  When the thickness of the part
'is selected from the list, this will automatically change the gauge number
'that is used in the part description.  (Kirk Arthur, June 2019)

'set the value initially to "n/a", then if no match if found
' this is what is shown for the parameter.

iProperties.Value("Custom", "Gauge") = "n/a "

Dim doc = ThisDoc.Document

Dim oThick_cm As Double = doc.componentdefinition.Parameters("Thickness").value' Value in cm

Dim Thickness As Double = Round(doc.UnitsOfMeasure.ConvertUnits(oThick_cm,"cm","in"),4)' Convert to inch

'Sets Custom parameter for 6 Ga.
If Thickness = 0.1943 in Then
	iProperties.Value("Custom", "Gauge") = "6"
End If

'Sets Custom parameter for 7 Ga.
If Thickness = 0.1793 in Then
	iProperties.Value("Custom", "Gauge") = "7"
End If

'Sets Custom parameter for 8 Ga.
If Thickness = 0.1644 in Then
	iProperties.Value("Custom", "Gauge") = "8"
End If

'Sets Custom parameter for 9 Ga.
If Thickness = 0.1495 in Then
	iProperties.Value("Custom", "Gauge") = "9"
End If

'Sets Custom parameter for 10 Ga.
If Thickness = 0.1345 in  Then
	iProperties.Value("Custom", "Gauge") = "10"
End If

'Sets Custom parameter for 11 Ga.
If Thickness = 0.1196 in Then
	iProperties.Value("Custom", "Gauge") = "11"
End If

'Sets Custom parameter for 12 Ga.
If Thickness = 0.1046 in Then
	iProperties.Value("Custom", "Gauge") = "12"
End If

'Sets Custom parameter for 14 Ga.
If Thickness = 0.0747 in Then
	iProperties.Value("Custom", "Gauge") = "14"
End If

'Sets Custom parameter for 16 Ga.
If Thickness = 0.0598 in Then
	iProperties.Value("Custom", "Gauge") = "16"
End If

'Sets Custom parameter for 18 Ga.
If Thickness = 0.0478 in Then
	iProperties.Value("Custom", "Gauge") = "18"
End If

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes