I selected a set of two of the surfaces you are working on.
(this because you merged many branches, where the underlying tree connection, I was not able, to trace back)
By selecting just two surfaces (and you will know how to select the many sets of two surfaces in your drawing), I made a “fresh start” .
Region Difference gives you the polyline you want. (with nicely sorted points. )
If the specifice starting point has to be moved:
explode the polyline
shift the vertices (shift list + slider) to where you want to start.
Most quick solutions run into dead-ends.
Probably most fast to
Create your grid
Create one panel with all variations you want.
Orient this one panel to all the points (planes) in your grid).
Everytime you use Flatten or Simplify, you loose tree branch informationen.
Looking at the result at “Merge” (just before where you want the points sorted), there is no way ( at least I did not see it) how to know what branches with points will form you polyline together.
So if you want to get the line from points (not from surfaces), you take care all tree-info is kept.
There are ways, to sort the points along a curve (to get them in a order)
or sort on distance to centre of group of points (to get the outer and inner groups)
and you have to find a way to connect the groups again.
Another approach is to get x, y and z values, and sort with them.
Give it a try and you will see that is a lot of work.
What I showed with the surfaces, works very fast and clear.
The other option is, that rebuild the whole thing and keep track of the place of every point in the datatree, so you can just pick them straight from there.
But as almost always there are other smart people on this forum who have better the solutions, maybe they will give them. Regards, Eef
@Eef_Weenink ‘s diagnosis looks correct to me. This is a symptom of an over-complicated underlying generation. Lots of making geometry, moving it, intersecting it, offsetting it, exploding it etc. A good recipe for a messy tree structure and the resulting “aaargh, looks like I have to flatten to make it work!”
When dealing with simple rectilinear profies like this, I prefer the “calculate all X and Y values then Merge them in vertex order” method. No geometric operations required. You do have to take a little care to make sure everything has the same tree structure. For example I multiply the “widths” tree by zero to get an indentical tree structure with a zero at each leaf.
Rather than untangle and transplant into your script, I have made a new polyline generator from scratch, which takes three inputs: the rectangular surfaces and two dimensions for the border offsets. This generates all the polylines on the XY plane at 0,0 then uses Map to Surface to transform them into place on the facade.
If this needs some other kind of shape, then I hope you can see how easy it would be to do different maths and assemble the vertices in some other order.