## Search the Community

The AUGI forums are an online community where AUGI members
can discuss what they use everyday,
Autodesk Design Software!

# Thread: Even/Odd detection formula for use in families

• ###### Display

1. 1 members found this post helpful.

## Even/Odd detection formula for use in families

Hi All,

I don't know if this has been done or not, or indeed if anyone else has ever wanted such a thing...

I have created a one-line formula that provides a boolean test (yes/no) of whether an input value is even or odd, for values greater than 1.

Create two parameters - one is the value you want to test. This must be an integer, so use either the integer class or use round(x) on another value. Let's use a parameter type integer, and call it TEST.

The second parameter is your boolean (yes/no) - call the parameter EVEN

Insert this formula in the formula field for the EVEN parameter:

Code:
`(rounddown(TEST / 2)) - (rounddown((TEST - 1) / 2)) > 0`
If the value of TEST is an even number, EVEN will be TRUE (ticked/yes); if TEST is an odd number, EVEN will be FALSE (unticked/no).

Where this might be useful:

I have used this in parametric door families for folder doors, to provide a boolean value to display the fixed leaf if an odd number of doors is used. I have also used it in shelving systems to allow a blank panel to appear when the shelves are odd. You might have some other uses for it.

Note that this will produce erratic results if provided with negative numbers, 0 or 1 as an input. This can be avoided through use of clever IF statements, and is left as an exercise for the reader.

How it works:

The formula tests the difference between a given value X/2 and (X-1)/2, with both values rounded down before the difference is performed. For an example value of 3 the equation is thus:

Code:
```Input values:  (3/2)  - (3-1/2) = (3/2)  -  (2/2)

Result values:   (1.5)  -  (1)

Rounded Down:   (1)  -  (1)  = 0 THEREFORE X is ODD where X=3```

For an example value of 42:

Code:
```Input values:  (42/2)  - (42-1/2) = (42/2)  -  (41/2)

Result values:   (21)  -  (20.5)

Rounded Down:   (21)  -  (20)  = 1 THEREFORE X is EVEN where X=42```

2. ## Re: Even/Odd detection formula for use in families

Clever! Have to keep this one around!

3. ## Re: Even/Odd detection formula for use in families

i remember an AU webinar from c2009 called something like fuzzy math for revit that had another rounding solution. yours seems simpler though. nice work!

4. ## Re: Even/Odd detection formula for use in families

http://aucache.autodesk.com/au2008/s...-1-Handout.pdf

heres the course handout. I guess it was AU08. the video was pretty interesting.

5. ## Re: Even/Odd detection formula for use in families

You made my folding door, odd-even panel number finally work in a simple way
I wish I could buy you a drink as thank you.
Just made my day (a sad life of a BIM manager when this stuff makes his day)

6. ## Re: Even/Odd detection formula for use in families

Here's another method that will get you there with a little less typing.
Code:
```Rounddown just strips off the remainder and gives you the whole number portion of the quotient.  So the following divides the test number in half and from that it subtracts the result of rounding down the quotient (thus giving you the remainder) and compares the remainder to 0.  If it's greater than zero, test is odd.
((test / 2) - rounddown(test / 2)) > 0```