Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic rule not working with specific decimal numbers

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
Anonymous
1169 Views, 11 Replies

iLogic rule not working with specific decimal numbers

Inventor pro 2017

 

Hi,

 

So basicly we have an iLogic rule that fill the part information depending on the thickness of the sheet metal.

 

At its core, it compares the thickness of the part with a value, if there is a match, it populations the description and such.

 

For some unknown reasons, the rule doesn't work when we input the thickness of a 12 gauge sheet: 0.1046

 

If I change the value for 0.1045 for example, it works just fine. I remeber during my school years that decimal are somewhat tricky due to the way they are calculated using binary. So, is it possible that 0.1046 falls into those few numbers that requires many bits in order to store the number correctly into a variable? And since there is not enough bits in the iLogic default variable the rule is not enough to work properly?

 

I am 100% sure that the only reason the rule doesn't work for that case is that specific number, and not something missing from the code (compared to all the other working code lines).

 

So I basicly want to know if my hypothesis is correct and what could be some potential fix to prevent such situation from rehappening.

11 REPLIES 11
Message 2 of 12
Xun.Zhang
in reply to: Anonymous

Hi @Anonymous,

 

It sounds like a defect for me, I'd like to invite the iLogic expect @JaneFan here to double confirm.

 

Thanks!


Xun
Message 3 of 12
JaneFan
in reply to: Anonymous

Hi @Anonymous, 

 

It is tricky, but would you please provide a simple model or some more details with which we can reproduce the issue? 




Jane Fan
Inventor QA Engineer
Message 4 of 12
Anonymous
in reply to: JaneFan

Hi,

 

Since I am only a consultant at this company, I don't want to share the templates, but I guess I can share some of the code lines.

 

'12 Gauge Mild Steel Sheet Metal
Else If Parameter("Thickness")=0.1046 in Then
iProperties.Value("Project", "Stock Number")="SPLT000115"
iProperties.Value("Project", "Description")="=12 GAUGE X <MATERIAL> X <Width> X <Length>"

With that, there is a User Parameter called G12 with a value of 0.104600 in. We input G12 in the Sheet Metal Defaults Thickness value, so that the Thickness parameter = G12 = 0.104600 in.

 

We do the same with other gauge, like 0.134500 for G10, and these work all fine.

 

My "fix" was to change 0.1046 to 0.1045 in both the code above and the G12 User Parameter.

 

I did try to simply copy and paste the code block from a working gauge, and simply changing the value back to 0.1046 but it still wouldn't work.

 

Tell me if you need more information.

Message 5 of 12
mcgyvr
in reply to: Anonymous

 

So if I understand you are doing "if statements" and they are simply failing because you haven't accounted for input outside of the given "ifs"..

 

Else
	MessageBox.Show("Hey dummy.. Thats not a correct thickness value", "Bad Entry")

 

Maybe you want to change to a dropdown selection versus someone entering information..

 

Why aren't they simply choosing the sheet metal rule vs manual entry which would help ensure they don't enter the wrong value..

 

 

 

 

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 6 of 12
Anonymous
in reply to: mcgyvr

I know that method is far from optimal in many ways, but as I said, I am simply a temporary consultant there using what they have been using for years.

 

I already passed the message that things could be done differently and more efficiently, but that is where my power ends, so in the meantime I am just trying to fix what I am working with.

 

Also, that is a very small portion of the code, if a value is outside of the regular values, it just returns thickness in the description, so if you type 0,1234 in, it will return 0,1234 in. But for some reason that specific 0,1046 value just causes the rule to not function at all, and changes nothing to the parts description. As if it knows it is trying to interpret that line which contains 0.1046, but fails to calculate something and just returns nothing and end as if it completed normally.

Message 7 of 12
mcgyvr
in reply to: Anonymous


@Anonymous wrote:

I know that method is far from optimal in many ways, but as I said, I am simply a temporary consultant there using what they have been using for years.

 

I already passed the message that things could be done differently and more efficiently, but that is where my power ends, so in the meantime I am just trying to fix what I am working with.


So what do you expect us to be able to do?

Will you give me their phone number so I can contact them and explain the problem properly?

 

From what you have posted so far (I'm going on very limited information) I think what I said is exactly correct in that you have code saying "If 1 or if 2" but no code to do anything if they input 3 right?

 

Would you like to share all the code so we can put in some error catching?

I gave an example of code that could be added as an else if all others fail..



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 8 of 12
Anonymous
in reply to: mcgyvr

updated my post above, but there is an else if statement.

Message 9 of 12
mcgyvr
in reply to: Anonymous


@Anonymous wrote:

updated my post above, but there is an else if statement.


Without the part and the full code we can only guess/assume..

Please post an example part complete with full code that shows the problem

You can easily strip out any proprietary information from that file..



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 10 of 12
Anonymous
in reply to: mcgyvr

There you go, modified it to return an error message when it doesn't match. As you can see, it is not able to compared 0.1046 with 0.1046 and returns 0.1046 in as a thickness instead of the 12 GAUGE in the description.

 

I think the number inside the rule or inside the parameter is just missing bits to properly calculate that number.

 

Same thing happens with wierd decimal numbers like 0.1047111111111

 

If I change the code to this, it works fine as well :

 

'12 Gauge Mild Steel Sheet Metal
Else If (Parameter("Thickness")>0.1045 in And Parameter("Thickness")<0.1047) Then
iProperties.Value("Project", "Stock Number")="SPLT000115"
iProperties.Value("Project", "Description")="=12 GAUGE X <MATERIAL> X <Width> X <Length>"
Message 11 of 12
JaneFan
in reply to: Anonymous

Hi @Anonymous, 

 

Thank you for the model. It is helpful to see the issue.

It seems an issue in iLogic paramerter, I will log it to the team to do further check.

There is a work around you can try: Using inventor parameter instead, replace the lines like this:

 

SyntaxEditor Code Snippet

Else If Thickness = 0.1046 in Then
iProperties.Value("Project", "Stock Number") = "SPLT000115"
iProperties.Value("Project", "Description")="=12 GAUGE X <MATERIAL> X <Width> X <Length>"

 

 




Jane Fan
Inventor QA Engineer
Message 12 of 12
MjDeck
in reply to: JaneFan

The problem is that the Parameter() function by itself doesn't always work as you would expect it to in equality tests. The best workaround is the one Jane posted: use the parameter name directly instead of using the parameter function.
Another way is to use the Parameter.ValueForEquals function:

ElseIf Parameter.ValueForEquals("Thickness") = 0.1046 Then

 

This is similar to the plain Parameter function, but it works only on numeric parameters. It provides a value that works more reliably for equality tests.


Mike Deck
Software Developer
Autodesk, Inc.

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

Post to forums  

Autodesk Design & Make Report