Change Duct Loss Coefficient to Another Fitting in ASHRAE Table

import clr
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.ExternalService import *
from Autodesk.Revit.DB.ExtensibleStorage import *
from System.Collections.Generic import *

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

def getServerById(serverGUID, serviceId):
	service = ExternalServiceRegistry.GetService(serviceId)
	if service != "null" and serverGUID != "null":
		server = service.GetServer(serverGUID)
		if server != "null":
			return server
	return null
lc=[]	
def getLossMethods(serviceId):
	service = ExternalServiceRegistry.GetService(serviceId)
	serverIds = service.GetRegisteredServerIds()
	list=List[ElementId]()
	for serverId in serverIds:
		server = getServerById(serverId, serviceId)
		#ductServer = server.IDuctFittingAndAccessoryPressureDropServer
		
		id=serverId
		name=server.GetName()
		lc.append(id)
		lc.append(name)
		lc.append(server)
		
	return lc
	

elems_=UnwrapElement(IN[0])
SetNew= IN[1]
elem=[]


elems=zip(elems_, SetNew)

for el in elems:
	eleId = el[0].Id
	fitting =doc.GetElement(eleId)
	param = fitting.get_Parameter(BuiltInParameter.RBS_DUCT_FITTING_LOSS_METHOD_SERVER_PARAM )#)
	lc = getLossMethods(ExternalServices.BuiltInExternalServices.DuctFittingAndAccessoryPressureDropService)

	schema = lc[2].GetDataSchema()
	
	
	field = schema.GetField("ASHRAETableName") 
	entity=fitting.GetEntity(schema)
	 
	oldval = entity.Get[field.ValueType] (field) # obtaining values
		
	TransactionManager.Instance.EnsureInTransaction(doc)
	entity.Set[field.ValueType](field,el[1]) # SetNew # installation of a new coefficient value of certain
	fitting.SetEntity(entity)
	TransactionManager.Instance.TransactionTaskDone()
	elem.append(fitting)

OUT = elem ,lc, oldval
2 Likes

and if you find way to set values to another category, please post here,

Hi Til

thank you for your effort, you’re very kind.

Your code works perfectly with Duct Fittings, too. The only problem was with Endcaps: they have only one connector, so Pressure Loss makes no sense with them. I just removed it with a list.filter in dynamo, and everithing worked perfectly.

Thank you!

ok . please paste your final code there (or dyn .file) . its may help to another people

1 Like

Here’s the final .dyn

Set ASHRAE table value according to a Type Parameter.dyn (17.7 KB)

2 Likes

Hello guys,
I’ve a code more or less like posted above and I got one question.
I’m changing method to specifc coefficient and set values.
It’s set in Revit properly etc, but calculated pressure drop parameter doesn’t take into account new value, it’s empty/blank. I need to select family in UI, change pressure loss method to any other method, hit apply and revert to specific coefficient again to get this working. Do you know how to force revit to update this properly and force revit to recalculate?. I don’t see anything different in my code, besides I didn’t wrap code into definitions.

Hello everybody,
I have also a question.
The second Python-Code is construed for only one single string.
If I want to put a list in the node, he give me a fault.
How can I solve this Problem?

Hi…Good script… I have a query…Can we get the field types…i.e from CR3-1 to CR3-9 in the list??. I was searching for the dynamo package and Revit API methods but can’t find any. Can you please provide me with the solution…Thanks a lot

hello everyone, could you tell me what are the steps to follow to run the file in dynamo thank you very much.

Thanks@til.shviger. Do we have any way to export the table inbuilt values to excel? From CR3-1 to CR3-10…

Hi, I am using @til.shviger code, but I am getting the same error all the time.

No method matches given arguments for Set: (<class ‘Autodesk.Revit.DB.ExtensibleStorage.Field’> , <class ‘str’> [‘File “”, line 74, in \n’]

The issue is in this line:

entity.Set [field.ValueType] (field,el[1]) # SetNew # installation of a new coefficient value of certain

I think it is becouse API have been updated as this post, but not sure how to implement this in Python

Many thanks

Hi @til.shviger , could you help us here to fix the code error that myself and @ignasi are having with recent Revit versions?
Thanks :slight_smile: