Create Circles, Divide and Connect Points from Gh to Py

Hi everyone, as a very simple exercise I created a very simple gh definition and now I am trying to to the same writing it in python.

The gh def simply creates concentric circles of different radius, divides them and makes a polyline thorough points.

I am having quite some trouble translating this into python:

Thanks to help in this forum I was able to create my own series of radii. I created the circles, but now I need to divide each one. The problem is that for loops do not take Guids as iterable objects…

Then I am wondering how I can perform a flip matrix on the list of points to connect them…
Thank you
Excercise01_Circles.gh (9.6 KB)

Any ideas? I am basically stuck at dividing multiple curves, what is the work around to not being able too loop Guid objects?

‘a’ is your list of circles.
‘Circles’ is a variable inside your for loop and only one circle at a time. And after the for loop ends holds the circle corresponding to your maximal I.

You try to iterate over the one GUID objet that is stored as ‘circles’.
Rather try iterating over a which is your list of circles. Ä
You can also use print statements to find obvious mistakes in your code.

print circles

For example will show the contents of ‘circles’

Right, I think the division is working now, but I cannot visualize the points, any idea why?

Excercise01_CirclesB.gh (10.9 KB)

Zoom in on the ghpython component and on the outputs click the ‘+’ icon. A new output called ‘b’ will be cteatesent. Append your points to a list b and you can visualize and use them

Yup yup that is what is I did, the points are appended to b. But the output from b, if connected to a panel actually reads: “IronPython.Runtime.List”.

Ah sorry you can either activate the preview of the ghpython component, or if you want to do more things with the points down the line plug them into a ‘pt’ component. If that doesn’t work maybe upload your current definition and I’ll take look.

Thanks! That would be ideal. I had uploaded just below the picture two replies previous to this one.

I think you are running into a “list of lists” issue. There are 2 options that you could do, (as your code exists).
1 : use an additional python component by simply setting a = x

2: use an additional import statement to access a “list to data tree” function (Rhino 6 only)

import rhinoscriptsyntax as rs
import ghpythonlib as gh

start = S
step = N
count = C

radii = [start + (i * step) for i in range(int(count))]

a = []
for i in radii:
    circles = rs.AddCircle([0, 0, 0], i)
    a.append(circles)

b = []
segs = E
for i in a:
    pts = rs.DivideCurve(i, segs)
    b.append(pts)

a = gh.treehelpers.list_to_tree(a, True, [0])
b = gh.treehelpers.list_to_tree(b, True, [0])

Mhmm I understand what you are saying, thank you.

I also found a solution from this thread by Giulio Piacentino.

He created a custom function that transforms nested lists of lists into GH DataTrees.

Needless to say this seems very inefficient, and overly complex for such a simply task, maybe an example where python is not the best tool…

The screen shot you show, (I believe), was before the function was available in “import ghpythonlib”. As of Rhino 6, you can just call the function direclty, (after importing ghpythonlib).

I think that the treehelper functions are pretty handy and straightforward when dealing with data trees. In the rhino 6 code I posted above, I only added 3 lines to what you had originally. I don’t think that’s an unreasonable amount of complexity.

1 Like

Indeed, but I have not upgraded to Rhino 6 yet, and I am thinking of all the time before Rhino 6 when someone wanted to do this and had to create the function manually, even more for an unexperienced user in Python like myself.

Anyways, thank you for the help Chris!

A post was split to a new topic: Grasshopper assistance request