Oct 10, 2022
Create Views with Revit API + python
We need to create Views for many different tools. So let's learn learn how to get correct ViewTypes and create views.
❓How to create Views with Revit API?
When you’re creating a view in Revit, there are a few things to keep in mind. First, you need to know what kind of view you want to create:
ViewPlan (FloorPlan, Ceiling Plan, StructuralPlan, AreaPlan)
ViewSection (Section, Callout, Detail)
View3D (Isometric, Perspective)
Once you have an idea of what kind of view you want to create, it's time to check Revit API documentation for specific methods on how to create such view.
👇 Here are their syntaxes. You can see in cyan color from what class it comes. (e.g. ViewPlan Class)
Let's look at each one of them to create views
0️⃣ Get all ViewFamilyTypes
But before that we need to prepare our code by getting all of the ViewFamilyTypes.
You will see across all of the methods, we always need to provide
viewFamilyTypeId. So let's start by getting and filtering all of View Types so we can use it later on.
Usually you will need to create some User control so they can choose specific ViewType, but I will just use a random one for this post.
1️⃣ How to Create ViewPlan?
Let's start by making a few ViewPlans.
ViewPlan is every horizontally cut plan that we use in Revit, such as Floor Plan, Ceiling Plan, Structural Plan, Area Plan...
And they all use the same method.
I have already shown you how to get
viewFamilyTypes so now it's about getting other arguments.
You can Copy-Paste these snippets and they will create views in your project!
2️⃣ How to Create ViewSection?
Sections are a little harder to make because we need to work with BoundingBox
👇 Here is the method to create a Section.
We have everything except for secitonBox. It might be tricky to create one, but it makes sense. Because when we create sections, we have a line where it cuts, and then it's view range is extruded, so it creates a sectionBox shape.
3️⃣How to Create View3D
Creating 3D Views with Revit API is straight-forward. We just need to decide between Isometric or Perspective.
👇 Here are their methods.
Create Isometric 3D View
Create Isometric 3D View
ViewDrafting is probably the easiest one to create
👇Here is the snippet
So you already know how to creat it.
5️⃣ Create View Sheet
👇Creating ViewSheet is a little different because we don't need to provide
viewType but we need to get
P.S. If you want to create a ViewSheet without title block you probably need to provide
ElementId(-1) . I haven't tried it, but knowing Revit API this should work.
6️⃣ Create Legend View
If you're trying to create a legend in Revit, the bad news is that there are no methods in Revit API for creating them.
The good news is that we can just duplicate any existing legend without detailing and we will have a new legend.
So for your tools where you want to create legends you need to verify that at least 1 Legend exists, so we can duplicate it! Otherwise, stop execution of your script and alert user that project needs to have at least 1 Legend to execute it.
👇I got all Legend views and checked if it's empty, then there are no Legends in the project and I need to alert user.
Once you made sure that you have a legend in the project, take a random one and just duplicate without Detailing.
And there you have it, a new empty Legend View.