Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic not interpreting parameter value properly (for only one condition)

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
jlane
512 Views, 6 Replies

iLogic not interpreting parameter value properly (for only one condition)

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

6 REPLIES 6
Message 2 of 7
GosponZ
in reply to: jlane

end if together?
Message 3 of 7
jlane
in reply to: GosponZ

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

Message 4 of 7
rossano_praderi
in reply to: jlane

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

 



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 5 of 7

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,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 6 of 7
jlane
in reply to: rossano_praderi

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.

Message 7 of 7
jlane
in reply to: Vladimir.Ananyev

Thanks Vladimir,

 

Dim Thk as DoubleForEquals = Parameter("Thk") solved it for me.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report