Feb 2, 2011 #1 BRENTA Industrial Joined Feb 2, 2011 Messages 8 Location US Hi everyone I'm in nx6 and trying to create an if/then based on X being odd or even. example if(x==odd)(1)else(0) Is there such a function or work around? thanks for your time.
Hi everyone I'm in nx6 and trying to create an if/then based on X being odd or even. example if(x==odd)(1)else(0) Is there such a function or work around? thanks for your time.
Feb 2, 2011 #2 JohnRBaker Mechanical Joined Jun 1, 2006 Messages 38,175 Location US OK, try this: test=mod(x,2) If x is ODD, test=1 If x is EVEN, test=0 Note that 'mod' is known as the 'Modulus' function and is documented in the Expression system's Function section under 'Math'. John R. Baker, P.E. Product 'Evangelist' Product Design Solutions Siemens PLM Software Inc. Industry Sector Cypress, CA http://www.siemens.com/plmhttp://www.plmworld.org/museum/ To an Engineer, the glass is twice as big as it needs to be. Upvote 0 Downvote
OK, try this: test=mod(x,2) If x is ODD, test=1 If x is EVEN, test=0 Note that 'mod' is known as the 'Modulus' function and is documented in the Expression system's Function section under 'Math'. John R. Baker, P.E. Product 'Evangelist' Product Design Solutions Siemens PLM Software Inc. Industry Sector Cypress, CA http://www.siemens.com/plmhttp://www.plmworld.org/museum/ To an Engineer, the glass is twice as big as it needs to be.
Feb 2, 2011 #3 JohnRBaker Mechanical Joined Jun 1, 2006 Messages 38,175 Location US And if there's a chance that 'x' could be positive or negative, it's safer to write the forumla as... test=mod(abs(x),2) ...as this will remove the effect of the sign of 'x' from the value of 'test'. John R. Baker, P.E. Product 'Evangelist' Product Design Solutions Siemens PLM Software Inc. Industry Sector Cypress, CA http://www.siemens.com/plmhttp://www.plmworld.org/museum/ To an Engineer, the glass is twice as big as it needs to be. Upvote 0 Downvote
And if there's a chance that 'x' could be positive or negative, it's safer to write the forumla as... test=mod(abs(x),2) ...as this will remove the effect of the sign of 'x' from the value of 'test'. John R. Baker, P.E. Product 'Evangelist' Product Design Solutions Siemens PLM Software Inc. Industry Sector Cypress, CA http://www.siemens.com/plmhttp://www.plmworld.org/museum/ To an Engineer, the glass is twice as big as it needs to be.
Feb 2, 2011 Thread starter #4 BRENTA Industrial Joined Feb 2, 2011 Messages 8 Location US That worked great, thanks for the help. Upvote 0 Downvote