Set element parameter by space number

Hello,

I made a link between an excel and mep spaces where it get the right values of flows and insert it in revit spaces. Now i want to count the number of air terminals in each space to distribute the flow evenly between those air terminals.
I managed to get the value needed to be set in each air terminal depending the space but i struggle to do the last step of the program where it set the flow’s value in each air terminal depending the space it’s hosted in.
I’m trying to code this in Python directly.

My idea is to iterate in the list of terminals and get his space and when his space number is the same that the key in the dictionary i set the flow parameter as the value corresponding to the key.
But i don’t know how to this because i lack knowledge in python and revit API

i came up with something like this that does not work :

a = IN[0] #Dictionnary with SpaceNumber:Flow value to be put in all air terminal of this specific space
b = IN[1] #List of air terminals

for i in b:
if Revit.Elements.FamilyInstance(b(i))==a.keys(i)
Element.SetParameterByName(b(i), “Flow”, a[Revit.Elements.FamilyInstance(b(i))]);
else
[…]

I’m a newbie and don’t know how to properly write this code.

hi @a.perraudin and welcome!
This is a way to set a LookupParameter, see script below.
If you want to set a builtinparameter you can change a.LookupParameter(“omschrijving”).Set(“test”) in a.get_Parameter(BuiltInParameter.BUILTIN_PARAM).Set(“test”)

You can set a parameter like this:


air_terminals = UnwrapElement(IN[0])

#Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

for a in air_terminals:
	a.LookupParameter("omschrijving").Set("test")
	


#Eind Transactie
TransactionManager.Instance.TransactionTaskDone()

OUT = "Done"

i’ve Been learning slowly to understand Revit API and how it works. I did not manage to simply retrieve my element’s space number to compare it to my dictionnary keys and set the parameter accordingly. But hey i’m learning.

Hi @a.perraudin,

Can you show me your script what you’ve got so far?

Not much worth anything, mostly ground work to set up a base knowledge of Revit API’s functionning.
I do have that :

def GetSpace(item,_phase):
	if isinstance(item, FamilyInstance):
		if isinstance(_phase, Phase):
			try: return item.Space.number[_phase]
			except: return None
Spaces=[]

for i in air_terminals:
	S=GetSpace(i,"Future")
	Spaces.append(S)

It’s not working for some reason. I understood i needed the phase to be added to get the space but simply feeding it a phase name don’t work. I’m using Revit lookup to get the nature of data stored in elements. I have a long way to go before i can do things outside of dynamo nodes and packages :slight_smile: . I’m not even considering comparing this to my dictionnary of SpaceNumber:Flow to set the flow parameter as i am struggling to just retrieve the space number the element is hosted in. Baby Steps.

This is the dynamo part :

Can you send a sample rvt file and your script?

Hello thanks you for trying to help. I managed to make a working program for my problem. My problem was actually much simpler than i thought. I was trying to match values through a space number. The thing is manipulating the lists/dictionnaries to have my data keeping the same structure throughout the whole process solve this problem. (As i am an idiot i did not even do this first)