i just want to set my collected values to a parameter… BUT i lost my way
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms)
rooms = collector.WhereElementIsNotElementType().ToElements()
t = Transaction(doc, "Set SpaceNumber")
def SetParameterByName(Element,ParameterName,Value):
rooms.LookupParameter(ParameterName).Set(Value)
t.Start()
param_c=[]
for i in rooms:
p = str(i.LookupParameter("Bauteil").AsString())
q = str(i.LookupParameter("Geschoss").AsString())
r = str(i.LookupParameter("Top").AsString())
a = "M03" + p + q + r
#param_c.append(a)
for r in UnwrapElement(rooms):
param_c.append(r.SetParameterByName(r,"SpaceNumber",a))
t.Commit()
OUT = param_c
If you’re going to use the Dynamo method you have to provide Dynamo objects. You’re currently providing Revit objects. The alternative is to use the Revit API to set the parameter values.
# Retrieve all rooms in the document
rooms_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType()
rooms = list(rooms_collector)
# Start a transaction to modify the parameter
transaction = Transaction(doc, "Set SpaceNumber Parameter")
transaction.Start()
for room in rooms:
# Check if the parameter exists in the room
space_number_param = room.LookupParameter("SpaceNumber")
if space_number_param:
# Retrieve the values of other parameters
bauteil_param = room.LookupParameter("Bauteil").AsString()
geschoss_param = room.LookupParameter("Geschoss").AsString()
top_param = room.LookupParameter("Top").AsString()
# Construct the value for SpaceNumber parameter
space_number_value = "M03" + bauteil_param + geschoss_param + top_param
# Set the new value for the SpaceNumber parameter
space_number_param.Set(space_number_value)
# Commit the transaction
transaction.Commit()