Sorry maybe I did not describe the question well. The thing is that I have bunch of lines that does not form neither a loop, nor are sorted. For instance there 9 lines in a flatten list, but they should form 3 loops.
Taking a bunch of curves and running the _PlanarSrf command followed by the _Split command using the original curves as dividers I can get (say 3) surfaces from the curves and then the solution above works for each surface.
It’s a bit hacky making surfaces from the curves and then curves from the surfaces but if it works…?
If that’s not accomplishing what you’re after or you are instead looking for an automated approach using a script or Grasshopper, please post a sample file and change the topic category (e.g. scripting, grasshopper) to get in front of the best people to answer it.
I have lot’s of C# that do various things on graphs … but let’s clarify the issue (speaking having the general case in mind [islands, that is]):
You have a graph (any graph) meaning a bunch of edges (lines or curves) connected with some way.
If the graph yields islands (i.e: they exist collection(s) of nodes not connected with other collection(s)) then you’ll need to cluster the edges first and then compute the VV, VE, EV etc etc connectivity (you’ll need trees with 2 dimensions, obviously) related with the DataTree of edge clusters. For instance this random (proximity) edges collection yields 8 clusters.
Recursion starts from index 0 on the VV meaning that the VV.Branch(0) contains the neighbors: 5,10,9,12,6. For each of these get the neighbors (i.e. VV.Branch(5), VV.Branch(10), …) and since you work by searching any cirquit both sides mastermind a way to keep track of the 2 way order of indices visited. If at any stage the Lists intersect you subtract the latest common from one of the 2, you reverse it and add the remaing range to the first list (or just reverse it and add all to a HashSet: crude but why bother?): that’s your closed cirquit. If any given neighbor-neighbor List contains 1 item … this means the obvious (orphan/naked node).
Note: if your edges are curves you’ll need an EV conn tree as well in order to sample the pieces into the cirquits.
BTW: Closed cirquits is a critical thingy for AEC matters. Anyway that’s from some demo graph made years ago with regard cirquits for my people in the practice (who claim that they understand [In fact, they don’t at all] C#, Recursion and other mysterious things).
Not sure if this helps, but I believe this formally would be the problem of finding the chordless cycles in a graph. Which, I suppose, is what MeshFromLines solves somehow. I believe the brute force graph approach would be to identify all cycles in the graph (which can be super heavy) and then filter out the ones that aren’t chordless. Anywho, some food for thought/Googling/PhD’ing