Revit vs Dynamo API

Hello,

I am starting to learn dynamo python through Primer. I am interested to know which of these two APIs I should concentrate on? Revit or Dynamo API? I would prefer concentrating on a single one, instead of both.
As I understood, Dynamo can also access Revit API (through UnwrapElement(IN[0])).

Learning Revit API can one day help in case I want to switch to Revit plugins, instead of using Dynamo.
But I see that Dynamo on the other hand is quite fast and powerful, and can achieve results in a matter of minutes, which is not the case with plugins.

Are there some opinions on which of these two APIs are more beneficial? The pros and cons?
Which one has more online examples?
What about documentation? Is there an online/offline Dynamo API alternative similar to revitapidocs?
Are there some important functionalities which Revit API has - and Dynamo API does not, and vice-versa?

I would be grateful to hear experiences.

you’ll effectively be learning both at the same time. Understanding what to do with dynamo nodes requires understanding the API, and eventually you’ll want to do something that’s easier to execute with a direct API call via Python (so you’re really learning 3 things)

But you can get pretty far with just dynamo nodes and designscript.

2 Likes

I recommend starting with neither API.

First learn how the nodes work directly, then transition into Design Script as it’s a great starter language for coding, and then move into Python (focusing on Python 3 as most of the Python 2 stuff is no longer necessary) and the relevant APIs (Both Dynamo and Revit as your will need both).

8 Likes

Hi @mclough , @jacob.small ,

Thank you for the replies.

I agree about learning standard dynamo nodes, but is learning Designscript that necessary? I would rather skip it, and go straight with the dynamo python.

I am familiar with python v2, and I don’t think the transition to python v3 (source, source2) will be that painful, as I am already using all the concepts mentioned in the ‘source’.

Where can I find API documentation for Dynamo (not Revit) classes, methods?
I found this:

https://dictionary.dynamobim.com/#/Geometry

but that’s documentation for standard dynamo nodes, not Dynamo API. Is there at least an offline Dynamo API documentation as some .chm file?

Sorry, by Dynamo API, are you referring to the actual Dynamo application API? If so, you should be able to find out more on Dynamo Github…

1 Like

Hi @Daniel_Woodcock1 ,

Thank you for the reply.
What I meant by Dynamo API are the properties and methods of the objects used inside the Dynamo Python node.

For example, ‘CutainPanel’ object inside Dynamo Python node has a property ‘Boundaries’, while its Revit counterpart ‘Panel’ object, has no such property.
Where can I find the Dynamo documentation on ‘Boundaries’ property?

I would recommend learning to use the inspect module in Python for much of this.

However the best way to learn this will be via DesignScript, as the node to code function will help you learn the notation, and those notations are pretty much 1-1 into Python.

1 Like

Ah, I see. I don’t think there is such API docs other than dynamo itself and Dynamo Dictionary. You could again always look on the Dynamo Revit Github…

But I think I understand what you mean in your initial question a bit better. I would recommend the following…

  • For anyone new to Programming/Dynamo, learn dynamo first as it will really boost your understanding of how programming works.

  • For anyone comfortable with Dynamo but new to programming/python. Start with converting your graph to code. This is pretty easy and can be done with any built-in node. As for Revit, I would start with Dynamo Revit and not pure Revit API, again, it’s easier to convert which gives a shallower learning curve than jumping straight into the Revit API.

  • For anyone that is comfortable with both python/programming and dynamo. Then jump straight into the Revit API. The Revit API has lots that Dynamo doesn’t have, particularly when you are using it in Plugins, so using dynamo as a sandbox is a good way to learn initially and also debug later.

2 Likes

Hi @Daniel_Woodcock1 ,
Thank you for the reply.
I see that link contains C# source code of the Dynamo itself.
I am stunned that after more than 6 years of its existence, Autodesk to this day does not have Dynamo API documentation.
I didn’t understand you this part:

If I am converting the graph to code, why do I need the built-in nodes? They are Dynamo standard nodes, thus not code nodes? Forgive me if I understood you incorrectly.

Hi @jacob.small ,
Thank you for the reply. too.
inspect module does not work on majority of Dynamo objects in IronPython2. Here is an example of its main getmembers function, and an error it produces:

inspect fail.dyn (6.1 KB)

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import sys

sys.path.append(R'C:\Program Files (x86)\IronPython 2.7\Lib')
import inspect



el_L = IN[0]
el = el_L[0]

OUT = inspect.getsource( el )  # raises an error:

TypeError: cannot access protected member internalElementId without a python subclass of CurtainPanel.

Nevertheless, I can use the dir instead. But that is not the point.

Where can I find that DesignScript documentation you mentioned? And I don’t mean the DesignScript language syntax, but the API (classes, properties) of Dynamo DesignScript?

I’m still not entirely sure what you are after. You used CurtainPanel.Boundaries as an example, but this is documented in the dynamo library view by going to Revit > Elements > Curtain Panel > boundaries. Or documented on the Dynamo dictionary site…

https://dictionary.dynamobim.com/#/Revit/Elements/CurtainPanel/Query/Boundaries

This returns a polycurve in which you can again just use either Dynamo App library to find what members this object has or again just use dynamo dictionary.

All public members for ds types have some degree of documentation. Is there a specific case where you don’t have documentation?

As for your question, why do you need the Built in nodes, well the built in nodes are the Dynamo Revit API (which is a limited wrapper around the Revit API which extends the Revit API in places or simply exposing it within a DS friendly context). As you said, the Revit API Panel doesn’t have this member called boundaries and in this case you may choose to save yourself some time writing the python code to get the boundaries and instead converting to DS object and then using OOTB CurtainPanel.Boundaries function. If you don’t want to use the built in nodes, then just use the Revit API directly which is also well documented. NOTE: If you are looking to write Plugins, then you also won’t be able to use the Dynamo OOTB nodes, so if you rely on functionality of a node (in graph or in code), you will need to write your own equivalent function from scratch or convert C# version to python in your own code.

1 Like

Thank you for the patience and helpful replies, once again @Daniel_Woodcock1

That makes it more clear for me now.
What I was hopping is that Dynamo API documentation has already been released, in the similar form to any other API documentation, or at least close to that. For example, this is the screenshot of the Revit API’s ‘Panel’ class from the ‘RevitAPI.chm’ SDK documentation shipped with Revit installation:

It clearly shows all the methods and properties of the ‘Panel’ class.

In Dynamo’s case, due to non-existence of the API documentation, I don’t know which other methods or properties exist for the ‘CurtainPanel’ class, because both Dynamo Library and Dynamo Dictionary show only 10 in total:


So what I would have to go to Dynamo Library/Dictionary: Revit → Elements → Element, and check which methods and properties are there, in order to know which additional ones are available for the ‘CurtainPanel’ class (because ‘CurtainPanel’ inherits from ‘Element’ class).
This is all very tedious, but I guess without the Dynamo API, there is no other way.

Thank you for the clarification on this as well.
The sentence which initially confused me is this last one:

This meant that I should start calling the same methods and properties in dynamo python node, as the names of the existing dynamo built-in nodes?
For example, there is a dynamo built-in node: ‘CurtainPanel.Boundaries’, so I would in dynamo python node call the property with the same name on ‘Revit.Element’ object.
Did I understand you correctly?

No worries. :slight_smile:

Yup, correct. That is because the Dynamo Revit “API” only has those 10 functions, there is no such thing as a CurtainPanel class in Revit (although we all know it as curtain panel), this is exclusively a Dynamo Revit object and created to wrap around and extend Revit’s Panel class with useful features (like CurtainPanel.Boundaries) which simply do not exist in the Revit API.

As for API docs, Dynamo does not need a .chm as it is in it’s own right sort of a .chm just with a prettier UI and where you can drag the members in a handy graph.

Kinda the same thing no?

Correct. The nodes in Dynamo are just method calls on an object, you can call these within python code. These all use the Dynamo Revit “API” if you will, not the proper Revit API. I write an article about this some time ago on how to execute Revit Nodes inside Python. It is no different from how you would with ProtoGeometry Nodes.

For example, the node Element.SetParameterByName can be written equivalently in python like this…

 elem = Revit.Elements.Element.SetParameterByName(e,n,v)

When using Dynamo Revit methods, you are limited to ONLY what is in the OOTB Library (Dynamo Revit API if you will), which is ever expanding, but still limited when compared to the Revit API. Using the Revit API directly is much more flexible down the line, but you can lose some useful functionality you had when using the Dynamo Revit API. But you can also use them in tandem by converting to and from DS/Revit types. Which type matters here, Dynamo Revit API can operate on DS Types and Revit API can only operate Revit Types (or unwrapped DS Types).

Hope that makes sense! :slight_smile:

2 Likes

Hi,
You can also use fuget

2 Likes

inspect.getmembers(el) should give you valid results.

1 Like

Thank you @Daniel_Woodcock1 ,
For the further explanations and your article. It was quite useful in clearing some of my doubts!

I would still disagree on the documentation of Revit API vs Dynamo API :slight_smile: . I am aware that ‘CurtainPanel’ and ‘Panel’ classes are not the same. I just gave them as a comparison.
Dynamo Library/Dictionary shows only 10 methods+properties, while in reality there should be 49 of them (the other 39 are probably inherited from ‘Revit.Elements.Element’ class).

@c.poupin ,
Thank you very much for the link. I was more looking for the Revit DesignScript Nodes API documentation.

Hi @jacob.small ,

On Revit 2019 and 2020; Dynamo 2.0.2 and 2.0.3; and Ironpython2, I get an error message when inspect.getmembers(el) is called.

Here is an example calling it on a Dynamo object:

And on a Revit object:

I attached the files.
example.dyn (7.4 KB)
example.rvt (3.0 MB)

An alternative to the dir() method for .Net objects

clr.GetClrType(el.GetType()) can be replaced by el.GetType()

2 Likes