I’m trying to use Python to get the air terminals in a mechanical system, so I wrote this (probably flawed) script:
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
Input = UnwrapElement(IN[0])
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
resultOut = []
if isinstance(IN[0], list):
for mepSystem in Input:
resultOut.append(mepSystem.Elements)
else:
resultOut.append(Input.Elements)
OUT = resultOut
My dynamo graph looks like this:

My question is:
Why does the output of the Python script display the element’s namespace? I’m expecting it to output the elements themselves.
Thanks for the info Deniz.
I’m getting this error though:
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 33, in
AttributeError: ‘ElementSet’ object has no attribute ‘ToDSType’
The node is outputting a null after changing the code as follows:
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
Input = UnwrapElement(IN[0])
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
resultOut = []
if isinstance(IN[0], list):
for mepSystem in Input:
resultOut.append(mepSystem.Elements.ToDSType(True))
else:
resultOut.append(Input.Elements.ToDSType(True))
OUT = resultOut
I looked up the ElementSet class in the API, but did not find any useful info there. I guess I’m confused about how to access the elements within the ElementSet instance.
@Frank_Loftus is this what you are looking for?
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
Input = UnwrapElement(IN[0])
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
resultOut = []
for e in Input.Elements:
elem = e.Id
f = doc.GetElement(elem)
resultOut.append(f)
OUT = resultOut
4 Likes
Excellent! This works perfectly. Thank you @Elie.Trad!
I suppose my error was not using the “GetElement()” method.
1 Like