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.

3 comments:

Don Magill said...

Thank you for this post. I found this very useful for allowing users to snap a pull-tab to ensure clearance, while allowing cut-lengths to be auto-incremented.
Parameters used:
1. IncrementSize - type
2. Pulltab - instance
3. IncrementedLength - instance
Formula:
= roundup(Pulltab / IncrementSize) * IncrementSize

Dave Clark said...

I, too, found this useful. I am incrementing multi-strand fibre-optic cables. So, Roundup (qty. strands needed / qty. strands per cable). I don't need the last multiplier because my increment is 1 (cable). For any quantity of strands greater than zero and up to the number of strands in a cable, it resolves to 1 cable, then 2 cables, etc.

Floyd Putnam said...

If revit just used standard excel syntax like ACAD does you'd just be able to use MROUND as well as use logic statements and text processing in your formulas and you would not have to come at problems like this sideways.