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 is being weird with numbers.

11 REPLIES 11
Reply
Message 1 of 12
GavoGarmo
908 Views, 11 Replies

iLogic is being weird with numbers.

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

 

 

Tags (3)
11 REPLIES 11
Message 2 of 12
swordmaster
in reply to: GavoGarmo

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

 

Inventor 2010 Certified Professional
Message 3 of 12
GavoGarmo
in reply to: swordmaster

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

Message 4 of 12
ekinsb
in reply to: GavoGarmo

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
GavoGarmo
in reply to: ekinsb

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

 

 

 

 

 

Message 6 of 12
ekinsb
in reply to: GavoGarmo

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
Message 7 of 12
MegaJerk
in reply to: GavoGarmo

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
Message 8 of 12
GavoGarmo
in reply to: MegaJerk

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

Message 9 of 12
MegaJerk
in reply to: GavoGarmo

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
Message 10 of 12
Carthik_Babu
in reply to: GavoGarmo

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......
Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 11 of 12
mrattray
in reply to: GavoGarmo

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

Message 12 of 12
GavoGarmo
in reply to: mrattray

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.

 

 

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

Post to forums  

Autodesk Design & Make Report