Set Parameter by Name, how?

Hello,

i just want to set my collected values to a parameter… BUT i lost my way :wink:

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

in Dynamo it is a easy task, but how do i this here…

KR

Andreas

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.

1 Like

@Nick_Boyts ,

at least i got no warning

BUT it remains empty, final aim is to set the compined strings

KR

Andreas

Why are you using two for loops?

Try this:


# 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()

2 Likes

@gerhard.p ,

i understand i use the variable first get the parameter
and the same variable to set the parameter

via my collection

ok it works … for any reason i have to use str(

1 Like

This is 100% ChatGPT code^^
I use it for everything I’m coding and making much more progress since I do because:

  • I can ask for every single step why it is coded like that and i get detailed explainations

  • I can ask to code some parts in a different way

  • I can ask to add or remove things.

  • the naming of variables is better as if I did it myself

And so on.
Give it a try

1 Like