Oct 20, 2022
Copy Elements with RevitAPI + Python
This article will show you how to CopyElements using Revit API and python. There are 3 CopyElements methods to choose from and I have examples for all of them included!
📄 RevitAPI Docs: CopyElements Methods
First of all let's have a look at the available methods in Revit API to copy elements.
Revit API has three methods to copy elements depending on how you want to copy.
NB! All these methods come from ElementTransformUtils class.
0️⃣ Prepare Elements to Copy
First of all let's prepare some base that will be used in all 3 examples, where we can get common variables.
You can see that we need to provide elements as
ICollection[ElementId] for all the methods.
I will create
List[ElementId since it's similar data type. Below you can see an example where I get all walls in the view and create a List out of it.
1️⃣ Method A: Copy Elements with Vector
Now Let's have a look at how to actually copy our elements. I will start with the simplest method: copy elements using a vector.
Here is the syntax.
It just means we need to define X,Y,Z coordinates of how we want to move elements.
We have everything prepared except for the vector. Creating vector is the same as defining a point. We need to use
XYZ() class and provide
x, y, z values to where we want to copy elements.
💡Keep in mind that Revit API uses feet as internal units.
For Example, let's say I want to move my elements 50 feet on the X-Axis, 150 feet on the Y-Axis, and we won't change their Z-Axis.
👆 This would be the vector that we need.
Let's combine the whole thing and make a script that will copy our walls with vector.
2️⃣ Method B: Copy Elements from View to View
Now let's copy elements between Views, here is the syntax:
💡 Bonus: We can also take views from 2 different projects and copy between them!
The second method is used to copy Elements across different Revit
This time we need to get
elements to copy,
destination view(can be another project),
Transform (change position or angle of selection),
I will be getting random views in my Project, make sure to adjust to your needs!
2️⃣🅰️Copy Elements between Views
2️⃣🅱️Copy Elements between Sheets
We use the same logic for copying elements between Sheets.
3️⃣ Method C: Copy Elements from Project to Project
Lastly, I am going to show you how to copy elements between projects. By now you should have a good understanding how to work with any of these method, but I will give you another example.
I am going to get all open projects and then take all walls from project A and copy them to project B.
Copying elements is not that hard once you know what methods are available and how to use them. Whenever you will need to copy elements, just reference this article again, and I am sure it will help you out multiple times!