Good afternoon, how can I enter the circuit numbers into the parameter I need?
pyreviters,tell me,please, is the logic of the code correct? first we must get the elements of the circuit numbers and then set the values in our desired parameter.
Just for the sake of sharing, as the conversation took place in private message, Here is one solution.
# -*- coding: UTF-8 -*-
from pyrevit import revit, DB
from pyrevit.revit.selection import pick_elements_by_category
doc = revit.doc
uidoc = revit.uidoc
selection = pick_elements_by_category(DB.BuiltInCategory.OST_ElectricalEquipment, 'Pick electrical equipment')
def getSystem(e):
equipment_system = []
try:
system = e.MEPModel.AssignedElectricalSystems # here the e variable was not there
if system:
for sys in system:
equipment_system.append(sys.Name)
return ",".join(equipment_system)
else:
pass
except:
pass
def SetValueToElementParameterByName(e, en, ev):
params = e.Parameters
for param in params:
if param.Definition.Name == en:
try:
param.Set(ev)
print('Parameter set to {}'.format(ev))
except:
print("no circuit name")
with revit.Transaction("circuit name to element param"):
for element in selection:
try:
system = getSystem(element)
if system:
SetValueToElementParameterByName(element, "my_param", system) # here the parameter name is 'my_param'
else:
pass
except:
pass