LINEs to ClosedPolyCurve

Hi,
Is there a way in python to join together a bunch of LINEs that have endpoints touching each other, to form either a ClosedPolyline, or better still a ClosedPolyCurve? (Without having to ‘manually’ iterate through all lines, and search at their endpoints)

Note that this need be done in Batch as having an operator manually select the lines and then have them processed is not an option.

In some cases a LINE will turn out to be an Inner Edge. (LINEs 0 & 9)

eg: 0 through 9 represent individual LINEs
I need to end up with 3 ClosedPolyCurves

 11111111111111111111111111111111111112
 8 9                                  2
 8   9                                2
 8      9                             2
 8         3333333333333333333333333332
 8         4         
 8         4         
 8         4         
 8         4 555555555555555555555555555
 8       0                             6
 8    0                                6
 8 0                                   6
 777777777777777777777777777777777777777

If there is a Rhino command that will at least just join together LINEs that have endpoints touching - then I could create code to “sort out” points with >2 lines emanating from them.

Thanks in advance,
Zoltan
FWIW, I’m totally new to Rhino and have no clue about high-level stuff like Grasshopper.
(But GIS data structur programming I’m “OK” with)

Hi @Rhino131
Take a look at CurveBoolean with DeleteInput=All, CombineRegions=No and then select the AllRegions option. In the second step, just press Enter for all available regions - it can be easily be macro’ed if you want to automate it.
HTH, Jakob

Hi Jakob,
Thanks for this pointer.
I will look, but running this in GUI is not an option
I will see if there is a RunCommand option/variation that does not require operator input.

Thanks and regards,
Zoltan

Hi @Rhino131
Sorry - didn’t notice the “Scripting” category :clown_face: My bad! Hopefully you’ll figure something out or get help from one of the begger brains! :slight_smile:
-Jakob

[tee hee] :slight_smile:

Assuming the internal loops are quads, you can implement the RhinoCommon Mesh.CreateFromLines method and draw a PolylineCurve through the vertices of the resulting mesh faces. Here’s a quick GHPython example demonstrating this logic (edit: Added triangulated NGons example):


230824_LinesToMeshBoundaries_00.gh (8.4 KB)

Sidenote @piac: It’s a bit odd having to wrap the input lines in a curve array to call this method. But it’s awesome to have it RhinoCommon :raised_hands:

1 Like

MeshFromLines - now that sounds like the real deal.

Many thanks for the pointer/nudge.

1 Like

No worries. If you’re dealing with many lines, this code will be more performant for extracting face loops: