Hi all!
I would ask you a support to identify errors in a IronPython based node for if-elif-else statement.
I have breakdown of Dynamo when running the pipeline I tried to develop.
This Python node should have as Input n lists of n items that are parameters and values inserted, and get, in the BIM model. It works when I use one input, but not the lists. I admit I am not great enough to write a Python script, so I think it is a very stupid error I do (even if the visual studion Validation does not give me any alert.
The code I write is:
s=IN[0]
l=IN[1]
n=IN[2]
g=IN[3]
r=IN[4]
t=IN[5]
f=IN[6]
if (s == "≤1/8" and l == "assenti" and n == "≤1/5 ≤50 mm" and g == "≤2/5" and r == "≤1/14 (7%)" and t == "≤1/10 (10%)" and f == "ammissibili, purchè non passanti"):
c="1"
elif (s == "≤1/5" and l == "assenti" and n == "≤1/3 ≤70 mm" and g == "≤2/3" and r == "≤1/8 (12%)" and t == "≤1/5 (20%)" and f == "ammissibili, purchè non passanti"):
c="2"
else:
c="3"
# Assegnare l'output dell'utente alla variabile OUT.
OUT = c
Here, the input are 6, but can be more, according to the number of elements I go to select in the model (it can vary case by case), so this is another question to be inserted as input definition. The output should be a list itself in a number equal to the number of elements selected in the BIM model.
This is because you aren’t iterating over the list of inputs, but instead working with each list as a number. You need to wrap the entire statement in a for loop, or utilize list comprehension to do so.
However because you indicated you have an N dimensional list, that it ‘it could be a list of values, or a list of lists of values, or a list of lists of lists of values’, you may find it easier to wrap the python on a custom node to facilitate the unknown structure of data and enable list at level and lacing per standard Dynamo.
s=IN[0]
l=IN[1]
n=IN[2]
g=IN[3]
r=IN[4]
t=IN[5]
f=IN[6]
c = []
def method_name():
for item in lst(s,l,n,g,r,t,f):
if (s == "≤1/8" and l == "assenti" and n == "≤1/5 ≤50 mm" and g == "≤2/5" and r == "≤1/14 (7%)" and t == "≤1/10 (10%)" and f == "ammissibili, purchè non passanti"):
c="1"
elif (s == "≤1/5" and l == "assenti" and n == "≤1/3 ≤70 mm" and g == "≤2/3" and r == "≤1/8 (12%)" and t == "≤1/5 (20%)" and f == "ammissibili, purchè non passanti"):
c="2"
else:
c="3"
return c, item
def method_name():
c, item = method_name()
return c, item
c, item = method_name()
I have the same breakdown (dynamo and Revit close)
import sys
def getKeybyValue(mydict, searchlst, default):
for key, valuelst in mydict.items():
if list(valuelst) == list(searchlst):
return key
return default
dataEnteringNode = IN
#transpose if list contain sublist
if all([isinstance(i, list) for i in dataEnteringNode]):
dataEnteringNode = [i for i in zip(*dataEnteringNode)]
else:
dataEnteringNode = [dataEnteringNode]
mydict = {
"1": ["≤1/8","assenti", "≤1/5 ≤50 mm", "≤2/5", "≤1/14 (7%)", "≤1/10 (10%)" , "ammissibili, purchè non passanti"] ,
"2": ["≤1/5", "assenti", "≤1/3 ≤70 mm", "≤2/3", "≤1/8 (12%)", "≤1/5 (20%)", "ammissibili, purchè non passanti"]
}
out = []
for sublist in dataEnteringNode:
i = getKeybyValue(mydict, sublist, default = "3")
out.append(i)
OUT = out
Note: when you post some code please usebutton after selection of your code