Families in Revit can be placed by points, hosts, and curves. Learn how to open a transaction, place families using point geometry, and update parameters in one short script.
- [Instructor] In an earlier video, we looked at placing a family using a point created in Dynamo. Now let's take a look at creating line-based elements such as walls and floors by utilizing what we've learnt so far. As you can see, I've created a polygon from a set of points that are driven by two lists of integers. Let's use these lines to create a floor in our Revit project. We can then use these same line to create walls that all sit on top of the floor. To find how to create a floor, lets switch over to Visual Studio and we'll search for the term floor.
As you can see in the floor element, there is no method to create a floor. This is because we need to use the new floor method found in the document.create namespace. This is quirk of the Revit API in which some of the creation methods are in this namespace from when the first Revit API was released. So, if we search for new floor We can see that there are actually three different ways of creating a floor. Let's choose the third type which takes a curve array and a boolean.
The curve array being the profile of the floor and the boolean specifying if the floor is structural in nature. The profile or curve array appears to be a Revit API object. This can be thought of as simply a list of curves. Let's go ahead and take a look at the object by clicking on it. As we can see, we can create a curve object by using the curve array method. And then we can use the append method to append curves to it. So, let's go ahead and input our polygon into Python and we'll create a floor using the new floor method. Go ahead and then open Python up.
And we'll assign the incoming lines to the lines variable, making sure to convert it to a Revit type. Using the method to Revit type. If we output this line's variable, we can see that we now have a list of Revit lines. Go ahead and Run. What we need is a curve array. So, let's go ahead and create the curve array object and we'll assign it to the C array variable.
And now that we have an empty curve array object, let's loop through each of the lines in the lines variable and we'll append it to the curve array. As the line inherits from the curve class, there shouldn't be any problem in appending this object type. And let's use the append method from the curve array object. Great. So, now that we have the curve array object with the lines that we have input, we can go ahead and create our new floor. To do that, we need to create it within a transaction. As you can see, I've already created one.
And we'll use the new floor method by accessing the document variable doc. And we can do this by accessing the doc.create class. Let's go ahead and assign it to the floor variable. For the parameters, we'll use the curve array object and false as its non-structural. Then let's go ahead and append our floor element to the output list, making sure to wrap it using the 2DS type method we learned earlier.
And use the parameter false as we want it to be Dynamo controlled. Then go ahead and change the output to our output list, and accept. And let's run. Awesome. So, you can see that we've created a new floor element. If we switch over to Revit you can see that there's indeed a new floor. Now, let's use the same input of lines to create walls within our project. To do this, let's have a look in visual studio on how to create a wall.
Let's go ahead and search for wall. And we can see that there's a wall class with several methods on how to create a wall. As the Revit API is updated from Revit version to version, more classes will contain their own creation methods. This is why the wall.create methods are found in the wall class. Let's use the create method that takes a document, a curve, a level ID, and the boolean.
And again, this boolean will determine whether the wall is structural or not. Before we can create it, let's insure that we have all the parameters. We already have the document and the lines, so all we need is the level ID in which we will create the floors. As we've just created a floor, if we switch back to Revit and select the floor, we can see that there is a floor parameter named level which returns level one. Let's get the value of that parameter, and we'll use it to create our wall. To get the level, let's create a variable name level and we'll assign to that the level that we want.
To do this, let's use the method in the element class look up parameter. And with this method, we can use a string to find the parameter with the name level. And as the level parameter is stored as an element ID, let's retrieve that parameter value using the method as element ID. Okay, now that we have our level ID, let's go ahead and create our walls. As we know, the wall create method takes a curve, and our Revit lines are a type of curve, so, we can loop through each of these and create a wall.
Let's go ahead and create another loop, looping through the lines list. And with each loop, let's create a variable named wall. And we'll assign to this a new wall using the wall.create method with document, align, the level ID, and the boolean false as its non-structural as the input parameters. Then let's go ahead and we'll append the wall variable to our output list, making sure to wrap the element.
And let's set it to false as we want it to be done on our own. Then go ahead and Accept, and Run. Perfect. So, you can now see that we have a floor and a set of walls output from our python script which, if we switch to our Revit project, we can see have been created within the Revit project. As we have wrapped both the walls and floors, if we update the input points our floor and walls will update automatically. Let's try this by setting one of the wire coordinates to say 8,000, and running it.
And you can see it's been updated in our Revit project. One thing to keep in mind when creating Revit elements is that each time we make a change in our script, the script is updating and recreating elements. Now, let's go ahead and have a look at how to adjust elements.
Note: This course uses Dynamo 1.3.1 and Revit 2018. For best results, it helps to have the same versions of the software.
- Importing the Dynamo Geometry library
- Defining variables
- Making decisions with conditionals
- Controlling flow with operators
- Defining functions
- Working with external libraries in Python
- Accessing the Revit API with Python