Revit API : FilledRegion

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.

FillRegionSample – Demo

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).

FillPattern Constructor

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)

figure 1.0 – FillPattern

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)

figure 1.2 – FillPatternElement & FillRegionType

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).

Create FilledRegion Method

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.

figure 1.3 – CurveLoop & FilledRegion

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.

Add-Ins Manifest File

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)

Author: min.naung

Founder and Developer @twentytwo.space

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.