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: 

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

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
JimStrenk
7319 Views, 4 Replies

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

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!  Smiley Sad

 

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, 2014, 2015,2016, 2017

Other than THAT, Mrs. Lincoln, how was the play??
4 REPLIES 4
Message 2 of 5
BrentDouglas
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
Message 3 of 5
JimStrenk
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, 2014, 2015,2016, 2017

Other than THAT, Mrs. Lincoln, how was the play??
Message 4 of 5
BrentDouglas
in reply to: JimStrenk

That's correct. Glad I could help.
Message 5 of 5
JimStrenk
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, 2014, 2015,2016, 2017

Other than THAT, Mrs. Lincoln, how was the play??

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

Post to forums  

Autodesk Design & Make Report