# Set Parameter by Name, how?

**URL:** <https://forum.dynamobim.com/t/set-parameter-by-name-how/90946>\
**Category:** Developers\
**Created:** [June 20, 2023, 8:48pm UTC](https://forum.dynamobim.com/t/set-parameter-by-name-how/90946 "2023-06-20T20:48:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 20, 2023, 8:48pm UTC](https://forum.dynamobim.com/t/set-parameter-by-name-how/90946/1 "2023-06-20T20:48:46Z")

</div>

Hello,

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

```auto
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

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/9/b909ecd29aef9a783ba06a72648f0d1ef84f0b76.png)

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

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [June 20, 2023, 9:01pm UTC](https://forum.dynamobim.com/t/set-parameter-by-name-how/90946/2 "2023-06-20T21:01:28Z")

</div>

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.

> **[Set Method (String)](https://www.revitapidocs.com/2022/956a1e23-cfe5-a60b-1ff9-0e8e33812774.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 20, 2023, 9:14pm UTC](https://forum.dynamobim.com/t/set-parameter-by-name-how/90946/3 "2023-06-20T21:14:59Z")

</div>

@Nick_Boyts ,

at least i got no warning

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/f/7f16ca3e55297223c34b22d0199784baa70025c2.jpeg)

KR

Andreas

---

<div class="post-metadata">

**Author:** ![gerhard.p](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gerhard.p/32/147675_2.png) [@gerhard.p](https://forum.dynamobim.com/u/gerhard.p)\
**Post date:** [June 20, 2023, 9:16pm UTC](https://forum.dynamobim.com/t/set-parameter-by-name-how/90946/4 "2023-06-20T21:16:13Z")

</div>

Why are you using two for loops?

Try this:

```auto

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

```

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 20, 2023, 9:18pm UTC](https://forum.dynamobim.com/t/set-parameter-by-name-how/90946/5 "2023-06-20T21:18:50Z")

</div>

@gerhard.p ,

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/c/6c16316104256577ec2d4cdc8566fb57777b777b.png)

via my collection

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/2/d2ea8679245e434b3cb094b088663702beda4986.jpeg)

---

<div class="post-metadata">

**Author:** ![gerhard.p](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gerhard.p/32/147675_2.png) [@gerhard.p](https://forum.dynamobim.com/u/gerhard.p)\
**Post date:** [June 20, 2023, 9:42pm UTC](https://forum.dynamobim.com/t/set-parameter-by-name-how/90946/6 "2023-06-20T21:42:55Z")

</div>

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
