I am having some trouble with a basic python function, and am need of help.
Basically, I am working on a furniture plan, and just learned that some cubicle panels only come in certain lengths. I want to check to make sure that our plans only show the correct lengths and the incorrect ones are highlighted.
In dynamo, I have collected all of the cubicles and their widths. I want to check if any item in the list is equal to 54" (4.5’) OR 66" (5.5’). If it is, I want to be able to do Boolean Mask filter to separate the types.
My issue is that I am checking a list and it is returning a single item. I want it to replace the 54 or 66 values with “invalid panel” and the ones that don’t equal those items to be “valid panels.”
Here is my python code, and an export of my workspace, along with a text file of the panel widths.
Any help is appreciated!!!
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
w = IN[0]
#condition
for i in w:
if w == 4.5 or w == 5.5:
w = "invalid panel"
else:
w = "valid panel"
#Assign your output to the OUT variable.
OUT = w
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
w = IN[0]
arr []
#condition
for i in w:
if i == 4.5 or i == 5.5:
arr.append(False)
else:
arr.append(True)
#Assign your output to the OUT variable.
OUT = arr
Firstly if w is a list of numbers (widths) then you are asking if that list is equal to 4.5 or 5.5. Instead you want to be asking if i == 4.5 or 5.5.
Secondly I would put arr = [] above the for loop and instead of w = "invalid panel" put arr.append(False) and similarly for w = "valid panel" put arr.append(True) and then finally, OUT = arr
The reason you are getting only one output is because you are only assigning to w, as it loops through w, you are assigning w each time and leaving only one item as w when the loop ends.
Thank you for the reply! That makes sense (asking each item in the list, rather than asking the list). This helped me out.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
w = IN[0]
arr = []
#condition
for i in w:
if i == 4.5 or i == 5.5:
arr.append(False)
else:
arr.append(True)
#Assign your output to the OUT variable.
OUT = arr
You could also swap those trues and glades for an workstation and a null, and wrap the whole thing in a List.Clean function to just get the objects (workstations) you are after.