Inventor Customization

## Inventor Customization

Distinguished Contributor
Posts: 147
Registered: ‎06-20-2006
Message 1 of 5 (1,117 Views)

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

1117 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!

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

Product Design Suite Ultimate 2012, 2013, 2014 & 2015

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

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```
Contributor
Posts: 18
Registered: ‎04-03-2011
Message 2 of 5 (1,112 Views)

# 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```
Distinguished Contributor
Posts: 147
Registered: ‎06-20-2006
Message 3 of 5 (1,106 Views)

# 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

Product Design Suite Ultimate 2012, 2013, 2014 & 2015

Other than THAT, Mrs. Lincoln, how was the play??
Illinois: Where we send more Govenors to prison, than on to retirement!
Contributor
Posts: 18
Registered: ‎04-03-2011
Message 4 of 5 (1,102 Views)

# 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.
Distinguished Contributor
Posts: 147
Registered: ‎06-20-2006
Message 5 of 5 (1,097 Views)

# 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