Excel Lists. Sublists. Python

Hi there, i’m just trying a workarround to map parameters from Excel to Revit with Python.
I’m attached the excel file and .dyn.
The goal is with keys (colum A) matched with (Code block in script) get the same values from the other columns.
I’m working with index match values, maybe a dict function would be better?
What should be the fast way?
It’s in order to map more than 5000 space parameter’s.
Thanks in advance
prueba.xlsx (8.1 KB)
pruebaExcel.dyn (18.7 KB)

# Activar la compatibilidad con Python y cargar biblioteca de DesignScript
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Las entradas de este nodo se almacenan como lista en las variables IN.
dataEnteringNode = IN

rvt = IN[0]
xls = IN[1]
values = IN[2]
# Incluya el código debajo de esta línea
list = []
ids = []
list2 = []
for i,x in enumerate(xls):
	for r in rvt:
		if x == r:
			list.append(x)
			#ids.append(xls.index(x))
			ids.append(i)
	for t,v in enumerate(values):
		list2.append(v[i])
# Asigne la salida a la variable OUT.
OUT = list,ids,list2

Using a dict would be much faster in this case. Organized something like this:

dict_xls = {
    'a' : [1, 2, 3, 4],
    'b' : [5, 6, 7, 8],
    'c' : [9, 10, 11, 12]
    }
rvt = ['b', 'c', 'd']
matches = []
for key in rvt:
    try: # Get corresponding values by key
        val = dict_xls[key]
    except KeyError:
        val = []
    matches.append(val)
OUT = matches

The index doesn’t really matter.

2 Likes

prueba.xlsx (8.1 KB)
pruebaExcel.dyn (23.7 KB)
Thanks @cgartland so in case of a big amount of elements is faster a dict function than a indexof and get item at index in Python?
Like that:
# Activar la compatibilidad con Python y cargar biblioteca de DesignScript
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

# Las entradas de este nodo se almacenan como lista en las variables IN.
dataEnteringNode = IN

rvt = IN[0]
xls = IN[1]
values = IN[2]
# Incluya el código debajo de esta línea
list = []
ids = []
list2 = []
for i,x in enumerate(xls):
	for r in rvt:
		if x == r:
			list.append(x)
			#ids.append(xls.index(x))
			ids.append(i)
for t,v in enumerate(values):
	aux = []
	for s in ids:
		if v[s] == None:
			v[s] = ""
		aux.append(v[s])
	list2.append(aux)
# Asigne la salida a la variable OUT.
OUT = list,ids,list2

Can you explain more clearly a little bit what you are trying to map with your values ?
Technically the dictionary has the shorter time complexity than list (array). For example, the delete, get, check if element in list or not is O(1) time complexity. And in the other hand, the List has O(n) time complexity.
So in case you have the large input, the difference will be easier to notice.

1 Like

I’m just looking for the fast way to achieve map space parameters with an Excel file.
The example is only 4 spaces but i have like 4000-5000 spaces.
So, if i make a dic, i have some values that i’m not intersting to map in revit.
In the other hand if i take them by index it’s more “easy” but dont know if its faster.
You’re right in a list to check is worse than a dict.
In the picture for example, in some cases i need only to map a certain values, not always the same rule, its for that making a dict should be more difficult.

Base on your pic, I assume you want to map the value like this:
{‘XX-105’:[1], ‘XX-102’:[41], ‘XX-101’:[22,32],‘XX-103’:[34,44,104], ‘XX-104’=[26,36]}
If so, dictionary is the best in this case. But you need to make sure there are no duplication for keys value.
And then, you don’t have to worry about the index everytime you try to modify or get value from dict. Just simply do like this revit_dict.get(XX-103)[1] == 44. This is better than get the index of XX-103 and then find the paired value in other list. When we put it into 2 lists, we have to make sure their index is correctly paired up.

Thanks @mrkevinht91 but in case the key has “n” parameter values to map, first i need to keep the correct parameters for each key (index for every row(keys))
There is another way to make more fast?

What is the condition that defines what parameter is “correct”? I.e. Why does parameter XX-103 have values defined in columns B and C, yet is only using values from columns D, E, and F?

Hi @cgartland its depending of the condition type of a space. If its vented only some parameters, if its heated and cooled the other ones.

In that case you have to show us how it checks those conditions. The original question makes the conditions look random so we thought you would hard-code the indices.

If it is dependent on the condition type, how are you retrieving the condition type from the excel file as it is not in your example?

Can you show the full graph/excel file so we can help?