iLogic is being weird with numbers.

iLogic is being weird with numbers.

Anonymous
Not applicable
1,190 Views
11 Replies
Message 1 of 12

iLogic is being weird with numbers.

Anonymous
Not applicable

Hi all,

 

I'm currently writing some code that checks to see if an update is needed in a part. (This is to avoid having to check out a part if it remiains uneffected by an assembly change) But I'm noticing something very odd. The code doing the check is:

 

If Parameter("Shelf","Depth") <> UnitDepth - 26 Then RunRule("ShelfSpec")

 

This however doesn't work correctly, and runs the rule even if the parameter is already correct. 

 

Experimenting I created a new parameter named "ShelfSetBack", set it's value to 26mm and rewrote the code:

 

If Parameter("Shelf","Depth") <> UnitDepth - ShelfSetBack Then RunRule("ShelfSpec")

 

This worked but I was annoyed that I had to create a new parameter for no apparent reason. Experimenting further I created another new parameter called "Test", set it's value to 0mm and rewrote the code again:

 

If Parameter("Shelf","Depth") <> UnitDepth - 26 - Test Then RunRule("ShelfSpec")

 

This again worked perfectly, but for no apparent reason. It seems that so long as the last part of the argument is a parameter and not a number it seems to work. 

 

Can anyone shed any light of this? (I've also tried writing the vaules into brackets)

 

Thanks in advance 

 

GavoGarmo

 

 

0 Likes
1,191 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable

Hi GavoGamo

 

Two things

For me i have to precede RunRule with iLogicVb.

like so iLogicVb.RunRule("my rule") otherwise i get a error message

 

secondly i do not see the behavior you are experiencing, for me the code performs as expected

 

0 Likes
Message 3 of 12

Anonymous
Not applicable

Hi,

 

Thanks, I'm aware of the requirement for the iLogicVb. I just like to abbreviate a little to make the post look less noisy.

 

I'd be surprised if someone could replicate the problem. I think it's a genuine glitch.

 

Cheers for taking a look

 

GavoGarmo

0 Likes
Message 4 of 12

ekinsb
Alumni
Alumni

I suspect you're running into the issue I discuss here: http://modthemachine.typepad.com/my_weblog/2013/08/comparing-floating-point-numbers.html

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 12

Anonymous
Not applicable

Hi,

 

You're very possibly right. But floating point issues shouldn't arise when using integers (which I'm using exclusively).

 

Thankfully I seem to have fumbled my way to a solution, but as I'm not a programmer by trade I was wondering if there were some more fundemental rules I was unaware of.

 

Thanks for the links though, it's quite an intereesting topic in it's self.

 

Cheers

 

GavoGarmo

 

 

 

 

 

0 Likes
Message 6 of 12

ekinsb
Alumni
Alumni

If you're using values from parameters directly then they'll be floating point.  If you're getting the value and assigning it to an integer before the comparison, then your correct and my post doesn't apply.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 7 of 12

MegaJerk
Collaborator
Collaborator

Could you post the actual code, and possibly a test part that is having this problem? I would be interested in taking a look at it. 




If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 8 of 12

Anonymous
Not applicable

Hi,

 

Unfortunately the file is too large, even when zipped and there's no real way to practically strip it down.

 

Thanks for offering to take a look though.

 

GavoGarmo

0 Likes
Message 9 of 12

MegaJerk
Collaborator
Collaborator

Have you tried moving the End Of Part to the top of the list? I know that sometimes it can reduce file size significantly. Heck, you could even remove all of the model elements and just leave the few parameters in question if that's acceptable (as a copy of course 😉 ). 

Any who. Thanks for your time! 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 10 of 12

Anonymous
Not applicable
hi,
Suggestion.....
hope u can save the file in sites like http://www.mediafire.com/
by creating your own account and share the link of the file that is uploaded in that site....
by this way u can share if u wish......
0 Likes
Message 11 of 12

mrattray
Advisor
Advisor
What is unitdepth? Perhaps try filtering both values into a variable defined as the doubleforequals type. If nothing else, we'll prove that precision isn't the problem.
Mike (not Matt) Rattray

0 Likes
Message 12 of 12

Anonymous
Not applicable

Hi mrattray,

 

'UnitDepth' is just the name of the parameter I use to define the depth of the assembly. (The assembly is a kitchen cupboard).

 

I'm not entirely sure what a double for equals is. I've been working in iLogic almost exclusively with very little Vb so I haven't really gotten my head around it yet. I think I established precision wasn't the problem when I created an extra dummy parameter that was set to 26 rather than using the interger 26. But I wasn't sure what a floating point was until a few days ago so I'm a little lost in that area too.

 

 

0 Likes