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)

Hi, i need the same nodes and dynamo part, can you help?

what do you mean ? All nodes are from dynamo base and packages you can access through dynamo. What are you trying to do ?

First of all, I apologize for using the wrong wording. There is a link to the issue I tried to solve above. I want to transfer room numbers to the air terminals as you did, but it gets the room numbers from wrong references, I couldn’t understand it because the dynamo you used is not in English, can you send me the code directly?

You won’t get much out of my code as even the parameters name are for a French Revit. So basically you want to :

  • Get which room an air terminal is in
  • From that space get the number
  • Fill the mark parameter inside the air terminal with the room number

For me the way it should be done is getting all the air terminals in your project and retrieve the room they are in (don’t forget to activate the room calculation point in the air terminal family and place it accordingly). The goal is to have a list of space and a list of air terminals. Then you can set a parameter by name inside the air terminals with the list of room numbers.

When i did this code i came upon a bug in the element in space node and i modified the code inside it following this post : Elements in Room vs Elements in Space - #6 by c.poupin

You seem to want the elements in room node i don’t know if it have the same bug. But you’ll need the archilab package to use it.
I’ll suggest you add : mepover,archilab,clockwork,Springs and data shapes to your dynamo it contains really usefull new nodes. it’ll make your work easier.

Edit : Should look like that i guess , it’s pretty easy to do (categories should be air terminals for you , for me it’s in french)

As long as you don’t modify the list you get from family instance the order is kept so filling each parameter from space in each air terminals will work. (if you want to use it with rooms change the node familyinstance.space by familyinstance.room) Plus if you’re using a linked model you should add a code to select the right link.

So it works i guess? I think you could have done a shorter code. The geometry translate to get room at point is basically re-doing the room calculation point already in air terminals.But hey as long as it works.

its doesnt work,this is really my last chance i need to finish this job , and here again it is assigning random room numbers as parameters to air terminals in the same wrong way please can you help me

you have coordinates problem thats why…try with some transform :wink:

how can i do it ?I also know that I have a coordinate problem. If you’re not going to come to me with a solution, please don’t reply again!

you were also the one who helped me enter the coordinate nodes like this but you are telling me that is your problem now i think you are kidding me