Hi all,
I am having difficulty to append item to a list with Python.
I am trying to keep at output the same data structure as the input and for that I am using two for loops.
Error is saying that (i) is out of range, but when I output (i) I have list 0, 1, 2, 3 what is matching to indexes of the branches
I am quiet inexperienced with Python and I am really grateful for all your help
Thanks in advance
@Faruk_B I don’t think you need to use range and then use it to call the sublist.
Instead try this:
wallsTrees = IN[0]
analyticalElements = []
for wallsTree in wallsTrees:
temp = []
for wall in wallsTree:
a = 5
temp.append(a)
analyticalElements.append(temp)
OUT = analyticalElements
@AmolShah thanks a lot, I tried and it is working for numbers. Thing is that I am trying to get analytical elements from the walls and when I try to append temp list to analyticalElements list I get error: expected Element got List
wallsTree = IN[0]
analyticalElements = []
for wall in wallsTree:
temp = []
for wall in wallsTree:
a = Element.GetAnalyticalModel(wall)
temp.append(a)
analyticalElements.append(temp)
OUT = analyticalElements
@Faruk_B It is not working because you are nesting another loop with the exact same variables (i & j).
What you did is
for i in j:
temp = []
for i in j:
Instead of doing
for i in j:
temp = []
for k in i:
Here you go again:
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
wallsTrees = UnwrapElement(IN[0])
analyticalElements = []
for wallsTree in wallsTrees:
temp = []
for wall in wallsTree:
temp.append(Element.GetAnalyticalModel(wall))
analyticalElements.append(temp)
OUT = analyticalElements
I hope this time you will copy the code exactly as stated above and not get creative in renaming the variables!
@AmolShah, thanks, I made it to complicated. Thank you again for your help it works perfect