Get Rectangular, Oval and Round Size from Duct Settings

Hi all, it’s possible to collect Rectangular, Oval and Round Size from Duct Settings from the active document with the three colums “Size”, “Used in Size List” and “Used in Sizing” ?
Actually I can only collect DuctSettings and GetDuctSizeSettings

Thanks in advance

Cheers

import clr

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Mechanical import *
from Autodesk.Revit.DB.Plumbing import *

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import TaskDialog

fec_DuctSettings = FilteredElementCollector(doc).OfClass(DuctSettings).ToElements()
GetDuctSizeSettings=DuctSizeSettings.GetDuctSizeSettings(doc)

OUT=fec_DuctSettings,[GetDuctSizeSettings]

Hi @paris

Is this what you want?
DuctSettings

Hi @Kulkul thank you for your answer, great! it’s exaclty what I’m looking for,
can you explain a bit more what methods/property are you used?
Cheers

Refer below for brief explanation:
https://thebuildingcoder.typepad.com/blog/2013/10/programmatic-access-to-duct-sizes.html

1 Like

Thanks @Kulkul how translate “foreach( KeyValuePair<DuctShape, DuctSizes> pair
in settings )” into python?
Cheers


for sizes in GetDuctSizeSettings:
	for s in sizes.Value:
    #Continue your code here to extract....

And also refer to .NET Dictionary class:

1 Like

Thank-you @Kulkul I’ll try your suggestion.
Cheers

Hi @Kulkul thanks for your link, I can now get the values, but this type of dictionary it’s actually over my head :slight_smile:
Have a good day.
Cheers

1 Like

Here is an alternative with nested Python dictionaries to find properties for one size

import clr
import System
import re
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Mechanical import *
from Autodesk.Revit.DB.Plumbing import *

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
sdkNumber = int(app.VersionNumber)

getDuctSizeSettings = DuctSizeSettings.GetDuctSizeSettings(doc)

def convertDiamValue(mepSize):
	value = mepSize.NominalDiameter
	if sdkNumber < 2021:
		value = UnitFormatUtils.Format(doc.GetUnits(), UnitType.UT_HVAC_DuctSize, value, False, True)
		return value
		
	else:
		value = UnitFormatUtils.Format(doc.GetUnits(), SpecTypeId.DuctSize , value, True)
		return value 

typeStr = IN[0]
sizeStr = IN[1]

mepSizeDict = {}
iterator =  getDuctSizeSettings.GetDuctSizeSettingIterator()
while iterator.MoveNext():
	pairValues = iterator.Current
	keyName = pairValues.Key.ToString()
	values = pairValues.Value
	# get all properties
	firstObjet = list(values)[0]
	getprops = clr.GetClrType(firstObjet.GetType()).GetProperties()
	#
	mepSizeDict[keyName] = {convertDiamValue( x) : {p.Name : p.GetValue(x) for p in getprops if re.search(r'Diameter', p.Name) is None} for x in values}

OUT = mepSizeDict.get(typeStr).get(sizeStr)
2 Likes

Hi @c.poupin great! Thank you for your reply, I’ll try to learn and modify your python code to find the way to create a dictionary like @Kulkul.
Have a good day
Cheers

2 Likes