How to create an if elif else statement with multiple conditionals (& operator)?

python

#1

OK, I must be missing something, this seems like it should be pretty simple.

What I would like to do is take in A (angle value), test if it is between zero and 180 or 180 and 360 in order to determine which values I want the node to output, X or -X. if the angle is 0, 180 or 360 I want a different Y set of values.

A will be a single value, X and Y are lists of values.

Please see python code:

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

A = IN[0]
X = IN[1]
Y = IN[2]
Return = []

if A>0 & A<180:
	Return = X
elif A>180 & A<360:
	Return = -X
else:
	Return = Y

#Assign your output to the OUT variable.
OUT = Return

I keep getting error:
TypeError: unsupported operand type(s) for &: ‘int’ and ‘list’


#2

Please post any code as preformatted text so it looks correct and can be copied for troubleshooting.
image


#3

thanks, my bad. will do in future


#4

Python uses and not & for conditional statements. That should be all you need for your statements, however if X and Y are lists, you’ll need to allow for that in your code as well.

Since -X is the only Return that modifies the list it’s the only one that needs to be changed:
Return = [-x for x in X]


#5

All this for organizing curtain panels starting at top left of exterior face. Maybe there is a cleaner way.

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

A = IN[0]
X = IN[1]
Y = IN[2]

Return = []

if A[0] > 0 and A[0] <= 90:
	Return = X
elif A[0] > 90 and A[0] < 180:
	Return = X
elif A[0] > 180 and A[0] < 270:
	Return = [-x for x in X]
elif A[0] >= 270 and A[0] < 360:
	Return = [-x for x in X]
elif A[0] == 180:
	Return = [-y for y in Y]
else:
	Return = Y

#Assign your output to the OUT variable.
OUT = Return

Thank you @Nick_Boyts

Attached is the .dyn in which I was using this python script.
It is far from finished, but the plan is to swap curtain panels based on values from excel. I thought I had seen a similar example before, but my search queries are coming up empty.
CurtainPanels_ByExcel_WIP.dyn (79.9 KB)


#6

Lets see if this .gif works when inserted.


This thread was the linchpin to facilitate swapping curtain panels based on an excel spreadsheet.