Write a parametric Revit family that creates a rectangular cube and provides input variables to control the length, height, and width of the cube
I'll write a Revit API script that builds the family for you: reference planes, a box extrusion locked to them, and Length, Width, and Height parameters.
I've written a C# Revit command that builds the family from the Generic Model template and saves it as ParametricBox.rfa in your Documents folder. If a project is open, it also loads the family into it.
How it works:
- It adds three type parameters under Dimensions: Length, Width, and Height. The defaults are 4′, 2′ and 3′.
- It adds reference planes named Left, Right, Front, Back and Top, and locks each face of the box extrusion to its plane. The bottom face is locked to Ref. Level.
- Length and Width are labeled dimensions, plus an EQ constraint that keeps the box centered on the template's center planes. Height is dimensioned from Ref. Level to Top in the Front elevation.
- To change the size, edit the values in Family Types or in the project's Type Properties. Use Flex to test it.
To run it:
- As an add-in: build
ParametricBox.csas a class library that referencesRevitAPI.dllandRevitAPIUI.dll. PutParametricBox.addinin%AppData%\Autodesk\Revit\Addins\<version>\, set its Assembly path to your DLL, and run the command from Add-Ins → External Tools. - As a macro (no compiling): paste the
BuildFamilymethod and the helper methods into a Macro Manager module. Then callNewFamilyDocument,BuildFamily, andSaveAsfrom a macro method.
The code uses the Revit 2022+ parameter API. For Revit 2021 or earlier, replace GroupTypeId.Geometry / SpecTypeId.Length with BuiltInParameterGroup.PG_GEOMETRY / ParameterType.Length.
Please encapsulate this logic in a Python script that can be run using Dynamo 3.x
I'll repackage the same logic as a Python Script node for Dynamo 3.x (CPython 3 / PythonNet), with the dimensions coming in as node inputs.
ParametricBox_Dynamo3.py is a Python Script node for Dynamo 3.x (CPython3 or PythonNet3 engine). It builds the same family as before: three parameters, reference planes with the box faces locked to them, labeled dimensions, and EQ centering. It saves the .rfa and loads it into the open project.
Setup in Dynamo:
- Add a Python Script node and set its engine to CPython3 or PythonNet3.
- Paste in the script and add inputs with + until the node has six (IN[0] to IN[5]).
- Wire up the inputs:
- IN[0]–IN[2]: Number nodes or sliders for Length, Width, Height, in your project's units (feet in an imperial project, mm in a metric one). The script converts them to Revit's internal units.
- IN[3]: String for the save folder. Leave it blank to save to Documents.
- IN[4]: String for the family name. The default is "ParametricBox".
- IN[5]: Boolean set to True to run. This stops it rebuilding the family every time you move a slider.
- Watch the node output for the saved path or an error message.
Running it again with new numbers overwrites both the .rfa and the copy loaded in the project. The new values become the family's default type. To resize instances you've already placed, change Length, Width, and Height in Type Properties.