Change Duct Loss Coefficient to Another Fitting in ASHRAE Table


#21
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

#22

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


#23

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!


#24

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


#25

Here’s the final .dyn

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


#26

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.