# Get Rectangular, Oval and Round Size from Duct Settings

**URL:** <https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550>\
**Category:** Revit\
**Tags:** python\
**Created:** [July 27, 2021, 1:16pm UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550 "2021-07-27T13:16:12Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [July 27, 2021, 1:16pm UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/1 "2021-07-27T13:16:12Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/c/bc8b317ad90191175701d919e49fa76f8b6d9e8b.png)

Cheers

```auto
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]

```

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [July 27, 2021, 3:26pm UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/2 "2021-07-27T15:26:06Z")

</div>

Hi @paris

Is this what you want?  
 ![DuctSettings](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/1/418fe411526719618d18a65b9290c932c07997b0.gif)

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [July 27, 2021, 3:37pm UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/3 "2021-07-27T15:37:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [July 27, 2021, 3:41pm UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/4 "2021-07-27T15:41:32Z")

</div>

> [@paris](#):
>
> can you explain a bit more what methods/property are you used?

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

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [July 27, 2021, 3:46pm UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/5 "2021-07-27T15:46:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [July 27, 2021, 3:52pm UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/6 "2021-07-27T15:52:32Z")

</div>

> [@paris](#):
>
> how translate “foreach( KeyValuePair\<DuctShape, DuctSizes\> pair  
> in settings )” into python?

```auto

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

```

And also refer to .NET Dictionary class:

> **[Dictionary Class (System.Collections.Generic)](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=net-5.0)**
>
> Represents a collection of keys and values.

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [July 27, 2021, 4:59pm UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/7 "2021-07-27T16:59:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [July 31, 2021, 3:41pm UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/8 "2021-07-31T15:41:58Z")

</div>

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

 ![Get Rectangular, Oval and Round Size from Duct Settings_D261](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/6/5641ef15bb09f4c38f7ae54e92aed3ef8fff7cf6.png)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [August 1, 2021, 10:01am UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/9 "2021-08-01T10:01:06Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/6/e691a9455f826e9fc05391a55ecd4ad39924da3e.png)

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [August 1, 2021, 10:18am UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/10 "2021-08-01T10:18:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tejash.Kalamkar3WNMY](https://avatars.discourse-cdn.com/v4/letter/t/85e7bf/32.png) [@Tejash.Kalamkar3WNMY](https://forum.dynamobim.com/u/Tejash.Kalamkar3WNMY)\
**Post date:** [November 19, 2024, 6:37am UTC](https://forum.dynamobim.com/t/get-rectangular-oval-and-round-size-from-duct-settings/66550/11 "2024-11-19T06:37:44Z")

</div>

Hi Paris, output looks great. could you please provide the dynamo script?
