Lists as inputs

Why wont the python component accept a list as an input - it only accepts singletons?

Type error: expected float got list

Heres my code. I’m trying to create 2 points at x = 10.0 and x = 5.0:

 

<span style=“color: #f92672; font-weight: bold;”>import</span> clr
clr.<span style=“color: #ffffff; font-weight: bold;”>AddReference</span>(<span style=“color: #e6db74;”>‘ProtoGeometry’</span>)
<span style=“color: #f92672; font-weight: bold;”>from</span> Autodesk.DesignScript.Geometry <span style=“color: #f92672; font-weight: bold;”>import</span> *
<span style=“color: #75715e;”>#The inputs to this node will be stored as a list in the IN variable.</span>
dataEnteringNode = IN
ptCentre = IN[<span style=“color: #ae81ff;”>0</span>]
rad = IN[<span style=“color: #ae81ff;”>1</span>]
t = IN[<span style=“color: #ae81ff;”>2</span>]
CS = IN[<span style=“color: #ae81ff;”>3</span>]

cirConstruction = Circle.<span style=“color: #ffffff; font-weight: bold;”>ByCenterPointRadius</span>(ptCentre, rad);
val = [<span style=“color: #ae81ff;”>10.0</span>, <span style=“color: #ae81ff;”>5.0</span>];
pt = Point.<span style=“color: #ffffff; font-weight: bold;”>ByCartesianCoordinates</span>(CS, val, <span style=“color: #ae81ff;”>10.0</span>, <span style=“color: #ae81ff;”>1.0</span>);
OUT = pt

python does not work like grasshopper or use replication like Dynamo.

 

When you call Point.Byxxx in python you must adhere to the signature of the method. This means if ByCartesianCoordinates wants a CS and a value of float, then that is what you must pass.

To create two points you can loop over the values like this, and call the point constructor twice

output = []

for val in vals:

…newpoint = Point.ByCartesianCoordinates(CS,val)

…output.append(newpoint)

OUT = output

(the … are tabs or 4 spaces)

Thanks Michael,

Thats good to know. I’m new to Python, so is this simply a formality of the Python syntax, or a current limitation of Python in Dynamo? Replication is incredibly powerful, it would be a shame if its only available in CodeBlocks. Alternatively, CodeBlocks could be upgraded so they have full access to all Dynamo methods.

 

Tom