Looping Through Curves

Hello everybody, I’m trying to intersect a plane and a mesh; then I’ll offset those curves until they intersect or something similar. I’m using GHPython, but the problem is, I cannot know how to loop through curves. My situation is as such:

As you see, I intersected the plane and the solid (lattice structure part is here), and I exploded them by CurvePoints in python. However, I need to access each of the curves separately. In the panel, I see that grasshopper has that information. How can I access them, so that I can loop through the curves? Then I will offset each curve as I told.

Thank you. I don’t know if it’s necessary but I’m adding the files, even though they are a bit messy.letsFindSomethingElse.3dm (945.8 KB)
letsFindSomethingElse.gh (103.5 KB)

Hello @staycoolish,

First, what you need to do, is flatten your latticeCurve input and set it to list access. If instead you want to deal with a tree as input, you need to convert the tree to a nested python list inside your script component. In order to accomplish this, take a look at these functions.

Now, to loop your latticeCurve list (when flattened beforehand), you simply need a for loop:

# Loops through the curves
for crv in latticeCurve:
    print crv

# This loops through the list by index
for i in range(len(latticeCurve)):
    print i
    crv = latticeCurve[i]

# This loops through the list by index and item (curve per iteration)
for i, crv in enumerate(latticeCurves):
    print i
    print crv

For nested lists (or list of lists), you need to use nested for loops, to access the curves in the sublists:

curves_nested_list =  [[crv00, crv01, crv02], [crv10, crv11, crv12], ...,  [crvX0, crvX1, crvX2]]

for i in range(len(curves_nested_list)):
    crvs_sublist = curves_nested_list[i]
    for j in range(len(curves_nested_list)):
        crv = curves_nested_list[i][j]
1 Like

Thanks a lot pirateboy, but unfortunately I couldn’t figure out some parts. I used Flatten Tree function of Grasshopper, then I exploded the flattened curve, and the vertices were just fine, as seen in the figure. However, I cannot access them in GhPython. I tried to do “list access” like this, is that correct?

As I told, the outputs from Explode Curve - Vertices are really what I want, but I cannot access them in Python, which can be seen here:

and here:

How can I access those shellCurve edges, do you have any idea? I fell I’m very close but I’m super unexperienced with Grasshopper…

Try this! It should provide a good start for what you want to accomplish.

division_vertices.gh (8.4 KB)

Grasshopper components and rhinoscriptsyntax do not always work the same way, output the same values or have the same features.
In the future, please refer to the developper docs, to check what functionality is provided by a function of the rhinoscriptsyntax.

In your case, rs.ExplodeCurves() only provides the GUIDs of the new segments. In comparison, the Explode Curve Grasshopper component provides the segments and the division vertices.

1 Like

Thanks P1r4t3b0y, I will try my best!