LearnRevitAPI

Sep 26, 2024

Still use Dynamo?

I teach Revit API with pyRevit.However, everything you learn can also be transferred to python nodes in Dynamo with very minimum differences.99% of Revit API code stays the same, but you should know about 1% that is different.

Because it might affect your scripts.So, let's get Dynamo Primer Template and rewrite it for pyRevit in this lesson.

Prefer Video? Click Here to watch:

Revit API Code Difference in pyRevit vs Dynamo

Get Template

Firstly, I will copy the template from Dynamo Primer. It will be great for comparison, because it already includes all the main differences.

Click here to open the Page. Copy the template to your local file, and let's go through it together.

Reference Modules

Firstly in the template you will notice that you have to always import clr to reference a lot of modules like RevitAPI, RevitAPIUI, RevitNodes, RevitServices...

In case of pyRevit it's already done for you behind the scenes, but in dynamo you need to include it in your code to get access to these modules.

.NET List<T>

However, if you would want to use .NET List[ElementId](), you would also need to use clr module and reference System module. This stay exactly the same for both pyRevit and Dynamo.

Revit Nodes

Unfortunately, a few things won't be available in Dynamo and pyRevit.

You won't be able to use RevitNodes from Dynamo in pyRevit and you won't be able to use pyRevit modules in Dynamo.

But this one is expected and not exactly the Revit API difference. But it certainly makes our life more convenient depending on what we use.

Variables

As you might know already, you will always need at least one of these variables:

  • doc - Document, refers to Revit Project

  • uidoc - UIDocument, refers to Revit UI of active project.

  • app - Application - refers to Revit App itself.

And there are different ways to get them. Check the code snippet below. Also notice that pyRevit has 2 options A and B.

Transaction

Lastly, when we make any changes in Revit API we need to use Transaction. These is like a guardian of your Revit project to avoid accidental changes.

It means that you can only change anything if you specifically Start and Commit the Transaction. So as a beginner you can relax and explore Revit API without fear of breaking something up.

Here is how to Create Transaction in pyRevit:

And here is how to do the same but with Dynamo

Just make sure that you get doc before you use it.

Summary

And these are the main differences between pyRevit and Dynamo. If you still have any questions and want to hear about small nuances, then check this full lesson here.



Enjoyed Newsletter?

Leave a Testimonial Here.

⌨️ Happy Coding!
Erik Frits

Join Newsletter

📩 You will be added to Revit API Newsletter

Join Us!

which is already read by 7200+ people!

Last Chance To Claim LIFETIME ACCESS. [~20 Seats left]