• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor Customization

    Reply
    Distinguished Contributor
    Posts: 110
    Registered: ‎06-20-2006
    Accepted Solution

    How to test for EVEN or ODD variable values with iLogic 2012?

    263 Views, 4 Replies
    07-03-2011 02:02 PM

    I'm attempting to build a sheet metal panel in a rectangular pattern both vertically and horizontally.  All holes in pattern are to be the same size.  The other criteria that the pattern MUST follow is that the hole pattern itself, whether square or rectangular MUST BE CENTERED on the sheet metal face.

     

    Using an iLogic Form, I am able to drive the dimensions for the sheet itself, the hole diameter, the number of rows and the number of columns.  I am also able to input offsets both/either vertically or horizontally.  When either or both the Number of Rows or the Number of Columns is odd, one (1) hole centrally placed on the sheet metal face allows  for my design intent to work properly.  When the hole pattern requires either an even number of Rows or Columns, an offset is needed.  Through some experimentation, I've been able to figure out the amount of displacement required to center this type of hole pattern.

     

    What I'm in need of is code to test that either the Number_of_Rows value is even or odd and Number_of_Columns is either even or odd.  After testing for even or odd iLogic needs to update the hole location both horizontally and/or vertically as needed.  Instructions on how to update variable with iLogic are also needed.  I'm a newbie!  :smileysad:

     

    Code would be similar to the following:

     

    Test Number_of_Rows for "oddness"

     

    If Number of Rows is odd then

      oHOFFSET = 0

     ELSE oHOFFSET = 3

    Parameter ("Horizontal_Offset") = 3

    END IF

     

    Any tips, suggestions or errata on testing a value for being even or odd would be greatly appreciated!

    Jim Strenk

    Inventor 2012 Certified Associate
    AutoCAD 2012 Certified Associate

    Product Design Suite Ultimate 2012 & 2013

    Other than THAT, Mrs. Lincoln, how was the play??
    Illinois: Where we send more Govenors to prison, than on to retirement!
    Please use plain text.
    Contributor
    BrentDouglas
    Posts: 17
    Registered: ‎04-03-2011

    Re: How to test for EVEN or ODD variable values with iLogic 2012?

    07-03-2011 10:34 PM in reply to: JimStrenk

    The modulo operator is what you're looking for (Mod in iLogic or % pretty much everywhere else). It returns the remainder after a division.

     

    If NumberOfRows Mod 2 = 0 Then
    	//Do even things
    Else
    	//Do odd things
    End If
    Please use plain text.
    Distinguished Contributor
    Posts: 110
    Registered: ‎06-20-2006

    Re: How to test for EVEN or ODD variable values with iLogic 2012?

    07-03-2011 11:00 PM in reply to: BrentDouglas

    bd727 wrote:

    The modulo operator is what you're looking for (Mod in iLogic or % pretty much everywhere else). It returns the remainder after a division.

     

    If NumberOfRows Mod 2 = 0 Then
    	//Do even things
    Else
    	//Do odd things
    End If

    Since I wish to test Odd first, I should use the following code:

     

    If Number_of_Rows Mod 2 = 1 Then

      // Do odd things

    ELSE

      // Do even things

     

    End If

     

    Would that be correct? 

     

    Thank you for your assistance.  It is greatly appreciated!


     

    Jim Strenk

    Inventor 2012 Certified Associate
    AutoCAD 2012 Certified Associate

    Product Design Suite Ultimate 2012 & 2013

    Other than THAT, Mrs. Lincoln, how was the play??
    Illinois: Where we send more Govenors to prison, than on to retirement!
    Please use plain text.
    Contributor
    BrentDouglas
    Posts: 17
    Registered: ‎04-03-2011

    Re: How to test for EVEN or ODD variable values with iLogic 2012?

    07-03-2011 11:21 PM in reply to: JimStrenk
    That's correct. Glad I could help.
    Please use plain text.
    Distinguished Contributor
    Posts: 110
    Registered: ‎06-20-2006

    Re: How to test for EVEN or ODD variable values with iLogic 2012?

    07-04-2011 01:25 AM in reply to: BrentDouglas

    Thanks a million!  I've just finished cigarette pack #3 trying to figure this stuff out.

    Jim Strenk

    Inventor 2012 Certified Associate
    AutoCAD 2012 Certified Associate

    Product Design Suite Ultimate 2012 & 2013

    Other than THAT, Mrs. Lincoln, how was the play??
    Illinois: Where we send more Govenors to prison, than on to retirement!
    Please use plain text.