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’
Please post any code as preformatted text so it looks correct and can be copied for troubleshooting.
1 Like
thanks, my bad. will do in future
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]
2 Likes
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)
3 Likes
Lets see if this .gif works when inserted.
This thread was the linchpin to facilitate swapping curtain panels based on an excel spreadsheet.
1 Like
What is wrong in following code? Error : ‘int’ object is unsubscriptable
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
Place your code below this line
Assign your output to the OUT variable.
sc = IN[0]
Return =
if sc[0] == 100:
Return = -20
elif sc[0] == 50:
Return = -50
else:
Return = 0
#Assign your output to the OUT variable.
OUT = Return
I am getting error in ‘elif’.
This is all related to if and elif.
Thank you for your reply.
at first look, Return is set as a list and only given one value seeing as it only accesses the first index of your input list. granted a list of one value is still technically a list. is your input a list? as erfajo stated, you might be better off creating a new post and reference this one, while including more information and any possible background files for review.