Get the Type's name of DuctType from Revit API.

Get the Type's name of DuctType from Revit API.

akarahay
Contributor Contributor
1,271 Views
7 Replies
Message 1 of 8

Get the Type's name of DuctType from Revit API.

akarahay
Contributor
Contributor

When drawing the duct, we have access to the type of each duct type with different routing preferences, see screen shot. How can we access the name of the type of round duct for example Round Duct with Taps or Tee version of the duct type?

Currently, I can access only the FamilyName, but not the element's name like Tees, for the round duct. Pleas advise!

Duct Type and Its Sub_Type.png

doc=DocumentManager.Instance.CurrentDBDocument

# Filter for MEPCurveType
FamCollector=FilteredElementCollector(doc).OfClass(MEPCurveType)
for Fam in FamCollector:
    FamilyT.append(Fam.FamilyName)
    #Select only hard Duct not flex duct
    if "Duct" in Fam.FamilyName and "Flex" not in Fam.FamilyName:
        DuctFamily.append(Fam.FamilyName)

 

Accepted solutions (2)
1,272 Views
7 Replies
Replies (7)
Message 2 of 8

architect.bim
Collaborator
Collaborator
Accepted solution

Hi!

Actually the only thing you need is to get the Name Property value. But if you are dealing with IronPython it will cause an Exception due to the specifics of this language. But there is a workaround, see the code below:

 

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import FilteredElementCollector, Element
from Autodesk.Revit.DB.Mechanical import DuctType

doc = __revit__.ActiveUIDocument.Document

duct_types = FilteredElementCollector(doc).OfClass(DuctType)
for duct_type in duct_types:
    print Element.Name.GetValue(duct_type)

 


Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 3 of 8

akarahay
Contributor
Contributor

Hi Max

Thanks for the solution! Actually, I am working Python Script in Dynamo, not in C#.  The Error was "The property cannot be read", using the method you have suggested (DuctType.Name was not allowed). Would you mind elaborating on the workaround in IronPython to get the value property of the Name of the duct type.  

akarahay_0-1683746456170.png

 

0 Likes
Message 4 of 8

architect.bim
Collaborator
Collaborator

Hi!

The code I have provided you written exactly in Python. And the workaround is the last line code:

Element.Name.GetValue(duct_type)

Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 5 of 8

architect.bim
Collaborator
Collaborator
Accepted solution

By the way, there is also another workaround. You can get the value of the "Type Name" parameter. But for me personally, the first variant makes more sense than this one.

duct_type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()

Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 6 of 8

akarahay
Contributor
Contributor

Thank again, Max! This line works for me: duct_type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString() .
But the "Element.Name.GetValue(duct_type)" still give me error. See screenshot below.

akarahay_0-1683773526474.png

 

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

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
#from Autodesk.Revit.DB import FilteredElementCollector, Element
from Autodesk.Revit.DB.Mechanical import DuctType
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

DuctTypeName=[]
ListDuctType=[]

#Get Current Project Doc
doc = DocumentManager.Instance.CurrentDBDocument

    
FamCollector=FilteredElementCollector(doc).OfClass(DuctType) 

for Dt in FamCollector:
    #Select only hard Duct not flex duct
    if "Duct" in Dt.FamilyName and "Flex" not in Dt.FamilyName:
        DuctTypeName.append(Dt.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString())
        ListDuctType.append(Element.Name.GetValue(Dt))

OUT=DuctTypeName,ListDuctType

 

Message 7 of 8

architect.bim
Collaborator
Collaborator

Oh I see. This happens because you are using CPython3 to run the code. It causes many issues. If you switch to Ironpython2 at the bottom of the Python Script node, it will definitely work (in latest versions of Revit and Dynamo there might be no Ironpython at the bottom, in that case you should install additional Dynamo package to use Ironpython2)


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 8 of 8

akarahay
Contributor
Contributor

After switching to IronPyhon2, it works! Thanks, Max! Really appreciate your help!