Xrev API Tools: Increase Productivity!

Feeds

Loading...

Wednesday, August 29, 2012

Revit Formula Rounding

Today I came across a circumstance where I needed to round a value in a family to be to the nearest 5mm increment (+ tolerance).

The Round functions in Revit only round to the nearest whole number.  So a little maths is required to achieve this.

EG:

I have a parameter called "Param1" that I want to drive "Param2" from.

Param2 = (roundup((Param1 + 5 mm) / 5 mm)) * 5 mm

Essentially what we are doing is first adding the tolerance we want, then dividing by 5 (the rounding increment we want), rounding this off to the nearest whole number and the multiplying by 5 again to give us the desired rounded dimension.

Pretty simple, but hopefully someone will find it useful.