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
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
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
I suspect you're running into the issue I discuss here: http://modthemachine.typepad.com/my_weblog/2013/08/comparing-floating-point-numbers.html
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
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.
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.
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
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!
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.