Python Script, Processing a List

revit
#1

I’m sure I am missing something very simple, but I am having trouble processing a list using a Python script.

I have a list of values ranging from 1 to 1000, that I want to process to give me a list of new values.
I am calling the input list ‘x’ and the output list ‘y’. The way I want to process is that if x<75 I want y=5, if 75<=x<200 I want y=10 and so on. What I have shown below works correctly for a single input, but does not process a list.

There are probably easier ways to do what I want, but any suggestions?

0 Likes

Phyton not working with List
#2

you are indeed. Your code only works on a singleton (i.e. one object, or in your case, a number). As you want to provide a list you need to store your result in a list and iterate over the input list. One method is a simple loop to iterate through the list (and python has some pretty powerful built-in itertools which you should check out on python.org which are more efficient than loops):

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

numberList = IN[0]

y = []
for x in numberList:
	if x < 75:
		y.Add(5)
	elif 75 <= x < 200:
		y.Add(10)
	elif 200 <= x < 500:
		y.Add(15)
	elif 500 <= x < 800:
		y.Add(25)
	else:
		y.Add(32)

#Assign your output to the OUT variable.
OUT = y
1 Like

Python Nodes Basics