I have some simple iLogic conditional code (partially shown below) that reads the user parameter “Thk” and then constructs a string for the parts list BOM. If the value is equal to one of our commonly used sheet metal thicknesses, the numeric value for the BOM with replaced with “10 GA.” or “11 GA.” etc.
Here’s what’s driving me crazy… This iLogic rule works perfectly for all the thicknesses except for when parameter “Thk” = 0.1046. In this condition, iLogic does not interpret it a being equal to the code, even though it is. When I change the code and parameter value to 0.1045 and re-run the rule, it works. Same thing for 0.1047, it works too.
Am I missing something here? Here’s my iLogic code:
'Mild/Carbon Steel
If Parameter("Thk") = 0.1345 Then
val_Thk = "10 GA."
ElseIf Parameter("Thk") = 0.1196 Then
val_Thk = "11 GA."
ElseIf Parameter("Thk") = 0.1046 Then
val_Thk = "12 GA."
ElseIf Parameter("Thk") = 0.0897 Then
val_Thk = "13 GA."
ElseIf Parameter("Thk") = 0.0747 Then
val_Thk = "14 GA."
'Stainless Steel
ElseIf Parameter("Thk") = 0.1406 Then
val_Thk = "10 GA."
ElseIf Parameter("Thk") = 0.1251 Then
val_Thk = "11 GA."
ElseIf Parameter("Thk") = 0.1094 Then
val_Thk = "12 GA."
ElseIf Parameter("Thk") = 0.0937 Then
val_Thk = "13 GA."
ElseIf Parameter("Thk") = 0.0781 Then
val_Thk = "14 GA."
Else
val_Thk = Parameter("Thk")
val_Thk = RoundToFraction(val_Thk, 1/16, RoundingMethod.Round) &""""
EndIf
extents_width = SheetMetal.FlatExtentsWidth
extents_width = RoundToFraction(extents_width, 1/16, RoundingMethod.Round)
iProperties.Value("Project", "Description") = "PL "&val_Thk&" x "&extents_width&""""
iProperties.Value("Custom", "BOM_Length") = SheetMetal.FlatExtentsLength
Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
Thx for your reply MisterZS. When I copied the code to the forum it did some funny things with the formatting. You're right, it needs to be "End If", which is how it is in my rule.
I've attached a snippet of how it looks in the iLogic edit rule environment
Hi jlane,
sorry me but I like to have a shorter code to read, don't be mad with me...I've used the "Select Case" statement instead of your "If elseif end if"... your code is correct and work fine....but the solution is commented in my code ( ' duplicated code ).
Select Case Test 'Mild/Carbon Steel Case 0.1345 val_Thk = "10 GA." Case 0.1046 ' duplicated value val_Thk = "12 GA." Case 0.1196 val_Thk = "11 GA." Case 0.0897 val_Thk = "13 GA." Case 0.0747 val_Thk = "14 GA." 'Stainless Steel Case 0.1406 ' duplicated value val_Thk = "10 GA." Case 0.1251 val_Thk = "11 GA." Case 0.1094 val_Thk = "12 GA." Case 0.0937 val_Thk = "13 GA." Case 0.0781 val_Thk = "14 GA." Case Else val_Thk = Parameter("Thk") val_Thk = RoundToFraction(val_Thk, 1/16, RoundingMethod.Round) &"""" End Select extents_width = SheetMetal.FlatExtentsWidth extents_width = RoundToFraction(extents_width, 1/16, RoundingMethod.Round) iProperties.Value("Project", "Description") = "PL "&val_Thk&" x "&extents_width&"""" iProperties.Value("Custom", "BOM_Length") = SheetMetal.FlatExtentsLength
Bregs
Rossano Praderi
Could you please check if casting parameter value to DoubleForEquals precision could solve this problem?
(in theory it is possible that parameter value is equal not to 0.1046 but to 0.10460000000001 ).
Round function is another option.
Dim Thk as DoubleForEquals = Parameter("Thk") ‘single-precision value Select Case Thk 'Mild/Carbon Steel Case 0.1345 val_Thk = "10 GA." Case 0.1046 val_Thk = "12 GA." Case 0.1196 val_Thk = "11 GA." Case 0.0897 val_Thk = "13 GA." Case 0.0747 val_Thk = "14 GA." 'Stainless Steel Case 0.1406 val_Thk = "10 GA." Case 0.1251 val_Thk = "11 GA." Case 0.1094 val_Thk = "12 GA." Case 0.0937 val_Thk = "13 GA." Case 0.0781 val_Thk = "14 GA." Case Else val_Thk = Parameter("Thk") val_Thk = RoundToFraction(val_Thk, 1/16, RoundingMethod.Round) &"""" End Select extents_width = SheetMetal.FlatExtentsWidth extents_width = RoundToFraction(extents_width, 1/16, RoundingMethod.Round) iProperties.Value("Project", "Description") = "PL "&val_Thk&" x "&extents_width&"""" iProperties.Value("Custom", "BOM_Length") = SheetMetal.FlatExtentsLength
cheers,
Hi Dshortway,
Thanks for the programming tip! I am new to iLogic and VB.NET, and will start using the "Select Case" statement as you suggested. It didn't solve the problem, but appreciate your feeback. Kudos.
Thanks Vladimir,
Dim Thk as DoubleForEquals = Parameter("Thk") solved it for me.