Welcome to the first tutorial of Revit API series, this post is to cover creating FilledRegion
object and the related objects such as FillPattern
, FillPatternElement
, FilledRegionType
… etc., for this we gonna need to create a Revit’s ExternalCommand Add-Ins.

You can follow the first part of this tutorial to setup the project. After setting up your project, fetch the current Document from ActiveUIDocument. Creating FillPattern
in the current document is actually a two-steps, the first step is create the FillPattern object. And then, create as FillPatternElement object in the current document (with an open transaction).


We chose the last FillPattern constructor which requires six parameters : Name, TargetType, HostOrientation, Angle (radian), Spacing1 and Spacing2. As you can see in figure 1.0, we have provided parameters’ values accordingly. (0.785398 radian is 45 Degree)

Next step, as I mentioned before we have to open a transaction to create FillPatternElement
from the created FillPattern
(“My Fill Pattern”). FillPatternElement’s Create
method requires two parameters : Document and FillPattern (figure 1.2). Before we discuss about FilledRegionType
, let’s jump our discussion to the require steps of creating a FilledRegion
. (Create FilledRegion Method)

As you can see from the below screenshot, FilledRegion’s Create
method requires four parameters : Document, FilledRegionType’s ID, ViewID and a List of CurveLoop.
In figure 1.2, to create a FilledRegionType, we have collected a FilledRegionType object from the current document and Duplicated with a new Name “New FillRegionType”. Set the Pattern parameters with the created (“My Fill Pattern”) FillPatternElement’s ID and PatternColor to Black (RGB value (0,0,0) is Black).

For ViewId parameter, we will just use the ActiveView’s Id of the current document. For CurveLoop parameter, we will just create a Square shape for simpler purpose. To do so, we construct the four corner points : start, right, up, left the XYZ points and create the perimeter lines by connecting these points accordingly. Now we have line1, line2, line3, line4 as the perimeter lines/curves of the square shape and just create a CurveLoop with these lines/curves.

We can now create our FillRegion object by providing the require parameters : Document, newly created our FilledRegionType (“New FillRegionType”), ActiveView’s Id and created square shape CurveLoop.
Lastly, don’t forget to create an Add-Ins manifest file for this ExternalCommand Add-Ins.

Well, that’s all for this tutorial, you can download the complete source code from here. Cheers!
(RevitAPI Docs’ screenshots are taken from apidocs.co)
Leave a Reply