Python variable index

Hey folks,

my use case:
a) 1 room including 5 walls (W1…W5) each wall has an area and an allocation value.
b) 2 lists: List1: impact value (CO2eq/m2) list for external walls (n=50), List2 impact value (CO2eq/m2) for internal walls (n=50).

My goal is to ask: When Wall has Allocation value 1 then WallArea * all values from List1, else WallArea * all values from List2.
The output should be:
For every wall a list out of 50 impact values, representing the total impact value for the entire wall.

Actually, it is a simple for loop, but I face problems with List IN[2] and [3] somehow IronPython doesn’t like these lists.

The most warning I get is:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 34, in
TypeError: object cannot be interpreted as an index

Whereas I believe the index is correctly written.

I tried to unwrap the elements, for IN[0] and IN[1] its fine, but he cant unwrap [2] and [3].

Any ideas? Thanks in advance.

1 Like

Unwrap works recursively and returns Revit elements unwrapped in the same list structure as the original input. You therefore don’t need your own function/nor iterate your inputs to unwrap each item. If you attempt to unwrap elements which cant be unwrapped (i.e. anything which isn’t a Revit Element), then the function returns your input unmodified.

Line 34 looks fine - maybe try discarding your def and calling UnwrapElement() directly on your inputs and see if that gets you any further.

1 Like

thanks for replying, tried it, and didn´t work.

File “”, line 42, in
TypeError: object cannot be interpreted as an index

same error as before.
BTW, i have tried the script with two simple lists as IN2 and IN3, there the script runs perfectly fine.
I really think there might be some problem in the creation of list 2 and 3.

Might there be anything to think of when using excel list, modified in dynamo python and using it again in another python?

There are a few things to check; are all your inputs lists? The exception is pretty clear so have you investigated the line where the exception occurs? Without seeing your code, my guess is you are either indexing an object which isn’t a list, or indexing a list but not passing an integer into the indexer. As you cant debug in the Python text editor, you could comment out all other lines, create a temp list, and append the items you are iterating then output them as this may help you to isolate the problem.

1 Like

have done this already, and the issue is based on the last two lists i get as in2 and in3.
these two lists are coming from here…

then i get the items at index as my new list inputs.

i did replace the last two lists already with simple lists as input, then it worked…
see here:

Ensure the data structure of you GetItemAtIndex nodes (looks like you’ve renamed them so I’m deducing this from the input ports), matches the data structure of your ‘simple lists’ and see if that solves things. Also check that the Excel data is always output as a 2D list and not a 1D list or singleton if say, only 1 row or 1 cell of data is imported. If it doesn’t then there’s your problem; inconsistent data structure.

1 Like

I believe so too. I will keep you posted if i figure it out. need to think over it how to restructure my lists.
anyways, thank you very much for you input and feedback.

You’re welcome - if you’re still stuck, post your graph as you’ll get more answers from other python-savvy forum members who will be happy to help.


still stuck, have tried to modify my list inputs without any success, in case someone had a similar problem, please be my guest. I just can´t figure whats wrong with the data structure.

Hi @JuliaKaltenegger

Drop xlsx file and dyn here.

1 Like

thank you so much.
you will have to create one room with walls and parameter, see in the dyn file.
181204-Population- -dynBIM.dyn (273.3 KB)

and the excel sheet for “get EXCEL VALUES and create material population x1, x2, x3”
KBOB_combinations_x_buildingelements_170601_181202.xlsx (44.7 KB)

@JuliaKaltenegger I’m confused why do i have to create rooms and walls. I thought your issue is related to excel and python inside dyn file.

in the python I am actually combining values from the geometry of walls, and from an excel sheet.
but yes you are right, you don´t need to create walls…just use simple list inputs. fine as well.

@JuliaKaltenegger Currently you where feeding string values. Just add String.ToNumber node and you will be good to go. Cheers!


Oh jezz, so easy. i didn´t expect that my lists were strings. thanks so much.

@JuliaKaltenegger Please mark the post as solved. You’re welcome!

1 Like