# Close Polyline Python/ rc.Geometry.Polyline

Hi all,

i want to make a simple recursion in Python.

I have a polygon, i explode it, evaluate each segment and want to stroke a line(closedPolyline) throw the points.

I didnt found a solution searching on the web, but i read in the help, that Polylines are closed if start and end points coincide, so i am a litte bit confused why it isnt closed.

Also i think there is something wrong in the first loop, i dont adds more than one curve to the list. Not sure why

RecRC.gh (13.4 KB)

You must add the first point to your list before creating a polyline. Then it’s closed:

1 Like

Hi Marcus,

thanks for your reply, suspected something like this, but didnt knew you can add to the list in this way:)
Thanks for showing somethhing really important!

I also try since yesterday to figure out why the iteration stops after 1 step. I thought it would go so on.
It is taking just the first Polyline in the list?
Hope not to bother, it will be the last thing on this, not triyng to make somebody doing my homework its just my own interest;)

Hi @horst,

you could use the Hoopsnake component to perform the recursion:

I’ve tested this under Rhino 5 only: PolylineDividerTest.gh (9.9 KB)

If it has to be a python component, let me know…

c.

Hi Clement,

i try to learn python thats why i would like to solve it in python.

i think after reading mor about recursion it has to be in a function so i tried getting closer to what i want to archieve.

maybe you can point in the correct direction?

@horst, see if this helps:

Note that the “curve” parameter has been set to “item” access. Below file was tested in Rhino WIP only:

PolylineDividerTest_Python.gh (5.9 KB)

c.

Hey Clement,

thanks a lot i will have a closer look after work, but it looks great!

hi clement,

thanks for your help, i looked at it closer now and have 2 questions maybe you could explain me:
i simplified a the function so that i am getting less confused.

in line 4: how to set up this parameters, values?
in line 5 how to skip this? i am trying to the most possible in rhinocommon instead of rs.

thanks a lot!

Hi @horst,

first, that line has a small typo, change `steps` into `loops`. You are setting these values up in the function call (line 24). Basically the function can be called with just the `id` as parameter, like so:

`a = DoSomething(curve)`

If it is called like that, it uses the default paramters (steps=1, parameter=0.5`) specified in line 4. In line 24 the function call is done with the inputs from GH, so you can access them with sliders.

Line 5: Somehow you must convert the object residing in the Rhino document to a RhinoCommon object. This is what this line does using RhinoScript (rs). If you want to get rid of it, you can do the same using 3 lines of code:

``````import scriptcontext
...
obj = scriptcontext.doc.Objects.Find(id)
curve = obj.Geometry
``````

c.

An alternative would be to use ‘Type Hint’ and set it to Curve.
You access type hints by right-clicking inputs.

Otherwise, as an alternative, the coerce part could be outside the function.

2 Likes

hi @clement and @piac,

thank you both. really apreciate your help!

like the way setting the curve as type hint.
Probably there comes the time i need to coerce some geometry fot that case i now should know how it works;)

@horst, you’ll need the coerciation mostly when running above script without GH, eg. from within the built in python editor.

c.

Dear Clement.
Why the PolylineDividerTest.gh with HoopSnake the output Polyline Curves are duplicated, I mean curve over the same curve for each interaction, how could I remove the duplicated Polyline Curves?
Thanks
Andres.

not sure how to get rid of that, i guess the fist item in each loop is required for the hoopsnake component to work.

Why not use my second (python) example component from above ? It’s a single component and does not have to explode the input polyline or starting / resetting the hoopsnake loop.

c.

Clement!