i know it looks a little bit messy, but that is exaclty what i want to fix. On the left side are parameters that i want in my list and the result should look exatly like the “List Create” node shows. In order to get the wanted result i needed to flatten almost every parameter because of the different levels in their lists. So my question is: is there a way to create a python script that flattens the lists and gives me a list that looks like the one from the “List Create” node?
many thanks in advance
Thanks for your suggestions! thats actual funny let em quickly change tha names.
But even then i still got the problem, that for example “Ortbeton - bewehrt” ist in a list in a list…
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
def flatten(lst):
flattened_list = []
for item in lst:
if isinstance(item, list):
flattened_list.extend(flatten(item))
else:
flattened_list.append(item)
return flattened_list
in1 = flatten(IN[0])
in2 = flatten(IN[1])
in3 = flatten(IN[2])
result = [in1,in2,in3]
OUT = result
End result is two core nodes more than the Python node, May outperform the Python in many cases as it doesn’t need to spin up another virtual machine for Python, and will be easier to maintain over time as those nodes are exceptionally stable.
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#flatten the list to get them on one level
def flatten(my_list):
flattened_my_list = []
for item in my_list:
if isinstance(item, list):
flattened_my_list.extend(flatten(item))
else:
flattened_my_list.append(item)
return flattened_my_list
#parametername and value by IN[]
hvactypecombined = flatten(IN[0])
penetrationtype = flatten(IN[1])
penetrationheight = flatten(IN[2])
penetrationwidth = flatten(IN[3])
penetrationdiameter = flatten(IN[4])
wallmaterial = flatten(IN[5])
walldepth = flatten(IN[6])
firerating = flatten(IN[7])
hvactype = flatten(IN[8])
#list of the parameters
my_list = [hvactypecombined, penetrationtype, penetrationheight, penetrationwidth, penetrationdiameter, wallmaterial, walldepth, firerating, hvactype]
OUT = my_list
you don’t need to print (OUT) because in Dynamo, “OUT” is already like print in Python.