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
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
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.