IF Statement with Python Script or DesignScript Code Block

I’m running into a wall while trying to work with IF statements in an efficient way. I just simply don’t know how to appropriately specify the code in the correct syntax. Here’s what I have so far. Any pointers would be greatly helpful.

import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
theaterWomen = IN[0]
theaterMen = IN[1]

theaterTotalLoad = []
theaterWomenBasins = []
theaterWomenToilets = []
womenBasins = []

menAndWomen = theaterWomen + theaterMen

def calcTheaterWomensBasins(theaterWomen):
	if theaterWomen == 0:
		womenBasins = 0
	elif theaterWomen <= 40:
		womenBasins = 1
	elif theaterWomen <= 70:
		womenBasins = 3
	elif theaterWomen <= 100:
		womenBasins = 4
    	else:
    		womenBasins = int(math.ceil(((theaterWomen-100)/40)+4))
    	return womenBasins

    theaterTotalLoad.append(menAndWomen)
    theaterWomenBasins.append(womenBasins)

#Assign your output to the OUT variable.
OUT = theaterWomenBasins`

The interesting thing is I don’t get any errors when the code runs, but I continue to get an empty list. My inputs as of now are simply two integers (I’m using 75 and 25 respectively).

Design Script…


womenBasins=(women==0)?0:(women<=40?1:(women<=70?3:(women<=100?4:(Math.Round(Math.Ceiling(((women-100)/40)+4))))));

4 Likes

Concerning the Python code: You’ve defined a function but you’re not calling it anywhere in the code. In fact you could easily leave it out in this case since the code isn’t that complex. I don’t know exactly what the desired output is, but if you try this you will probably get something more to your liking:

theaterWomen = IN[0]
theaterMen = IN[1]

theaterTotalLoad = []
theaterWomenBasins = []
theaterWomenToilets = []
womenBasins = []

menAndWomen = theaterWomen + theaterMen

if theaterWomen == 0:
womenBasins = 0
elif theaterWomen <= 40:
womenBasins = 1
elif theaterWomen <= 70:
womenBasins = 3
elif theaterWomen <= 100:
womenBasins = 4
else:
womenBasins = int(math.ceil(((theaterWomen-100)/40)+4))

theaterTotalLoad.append(menAndWomen)
theaterWomenBasins.append(womenBasins)

#Assign your output to the OUT variable.
OUT = theaterWomenBasins``

Vikram,

Thanks for this. This is exactly the kind of solution I was looking for!

Makes sense. Thanks for the input. I think for now I will go with the Design Script route, but I will certainly keep this in my pocket. I’m sure I’ll need it.

Here’s a link to an alternative design script solution: