iLogic Parameter function behaviour

iLogic Parameter function behaviour

Anonymous
Not applicable
916 Views
10 Replies
Message 1 of 11

iLogic Parameter function behaviour

Anonymous
Not applicable

In the attached part, I don't understand why these two rules produce a different result:

 

Rule 1
If Parameter("glass") = 21.5 Then
     MsgBox("Standard")
Else
     MsgBox("Non-Standard")
End If


Message - Non-Standard

 

Rule 2
If glass = 21.5 Then
     MsgBox("Standard")
Else
     MsgBox("Non-Standard")
End If

 

Message Standard

I need to use the Parameter("glass") format as it's going to be an external rule, but I'm totally miffed as to why its producing the result it is.

 

Anyone able to provide some insight?

0 Likes
Accepted solutions (1)
917 Views
10 Replies
Replies (10)
Message 2 of 11

b_sharanraj
Advocate
Advocate

I feel like its not considering the decimal values.

 

Change that to some whole numbers and check once its working fine. Don't know exactly why its not taking decimal values.

Regards

B.Sharan Raj

0 Likes
Message 3 of 11

Anonymous
Not applicable

Hi @b_sharanraj

 

It's not that... Try it with 17.5 instead of 21.5 and it works as it should

0 Likes
Message 4 of 11

b_sharanraj
Advocate
Advocate

You can try like below code it may help you

 

Dim Temp_Glass as Single
Temp_Glass = Parameter("Glass") 

If Temp_Glass = 21.5 Then
MsgBox("Standard")
Else
MsgBox("Non Standard")
End If

If Glass = 21.5 Then
MsgBox("Standard")
Else
MsgBox("Non Standard")
End If

 

Regards

B.Sharan Raj

Message 5 of 11

Anonymous
Not applicable

Works normally when I change the value to 20.5 or 22.5. It doesn't like 21.5 Smiley Mad

0 Likes
Message 6 of 11

Anonymous
Not applicable

Your method does work around the problem, thanks for that.

 

I'm hoping someone at Autodesk can confirm if this is a bug?

0 Likes
Message 7 of 11

b_sharanraj
Advocate
Advocate

Bravo @Anonymous

 

You find out a bug Smiley Very Happy

 

Yes it have some problem only with 21.5 

Regards

B.Sharan Raj

0 Likes
Message 8 of 11

LukeDavenport
Collaborator
Collaborator
Accepted solution

 

There's already an interesting thread on this kind of rounding problem:

 

https://forums.autodesk.com/t5/inventor-customization/attack-Of-the-DoubleForEquals/td-p/5808334

 

(be warned its quite a complex thread!)

 

To summarise it - the issue is already logged as a bug with Autodesk. The suggested workaround to reduce these problems is to declare parameter values as Decimal.

 

Dim b As Decimal = Parameter("glass")

 

This works fine.

 

Although here's a couple more alternatives for you if you'd rather not have to 'Dim' your parameter on a separate line:

 

Alternative 1:

c = Parameter.Param("glass").Value * 10 

 

This is so-called 'advanced iLogic syntax' and it gets you access to the parameter object in the API. Note you would have to multiply by 10 if you’re working in mm (due to Inventor’s internal units of cm)

 

Alternative 2:

d = ThisApplication.ActiveEditDocument.ComponentDefinition.Parameters("glass").Value * 10 

 

' This is pure API code - obviously the path to the parameter object can be shortened!

 

Hope this helps,

Luke

Message 9 of 11

LukeDavenport
Collaborator
Collaborator

 

I should also have pointed out that for Alternative 1 and 2 above you don't actually need to declare the parameter value, so you don't need to write (for instance):

 

Dim c As Decimal = Parameter.Param("glass").Value * 10 

 

You can simply write:

 

c = Parameter.Param("glass").Value * 10 

 

If anyone is interested in the reason for this, its because the methods shown in Alternative 1 and 2 return a Double object (for numeric 'dimension' parameters), which compares fine with other numbers, but the Parameter("glass") method returns an iLogic DoubleForEquals object - which doesn't currently play well when compared to other numbers.

0 Likes
Message 10 of 11

HermJan.Otterman
Advisor
Advisor

hello,

 

did you try to "Round" the parameter before the compair?

I had some issues where 3 is not 3, but 3.000000001134252..

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 11 of 11

Anonymous
Not applicable

@LukeDavenport Thanks for the insight Luke, I can work with one of these methods.

0 Likes