Dealing with lists and Python nodes

So this is feels like a basic question, but it makes me realize that i’m probably missing something fundamental about how to write python scripts for dynamo.

i’m trying to write a script that will make a list of strings describing the detail level i want to associate with different scale values. The input is the output of Element.GetParameterValueByName, which should be a list of integers(?) Part of my problem is that i don’t always know what data types are coming out of the various dynamo nodes.

> 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.
> scales = IN
> dL=[]
> # create a list of strings based on the value of values in the list scales
> for s in scales:
> 	if s<=48:
> 		dL.append("Fine")
> 	elif s<=96:
> 		dL.append("Medium")
> 	else:
> 		dL.append("Coarse")
> #Assign your output to the OUT variable.
> OUT = dL

when the code runs, i get a list with length 1, and the value “Coarse”

I’ve tested the code in the python shell, and it works as intended, so i think i’m misunderstanding something about how the inputs to the python script block are structured.

What am i missing here?

Try changing scales = IN for
scales = IN[0].

Your inputs are a list, you should define which item of this list each input is


yes. that seems like that should have been obvious. so
scales = IN
makes scales a list of length 1 that contains the list of scales, right?
scales = IN[0]
sets scales as the 0th entry in IN, which is my list of integers

Python defines all your possible inputs as IN.
The node allows you to determine the number of inputs you use. You can even see on the node each input is labeled (IN[0], IN[1], IN[2]…etc) So what you’re actually saying is from my list of inputs, the first input (IN[0]) will be defined as scales.

1 Like