I’ve got a list of linelike curves which all coincide at their end and shape a polyline(except it is not joined) . the problem is that little lines in the list are not sorted along the polyline. if I join them it would be one curve . but I dont want to! how can i sort these list of lines that if i start to select them base on their indices it goes from one end of polyline to the end continuously!I hope you understood!
Try the JoinCurves function.
Well I guess you could use the JoinCurves Function, and then use the Vertices (obviously they will be “in order”) to create ordered Lines. Or have a joined copy and select your existing lines with some sort of closest Point selection.
Maybe Rhino.SortPointList could help in some way too, although I’m not sure about how it works and what you would exactly need
Just my very amateurish answer, but maybe they help…
The problem I have is that I have a list of data for each line that after joining the line I lose the connection.(I have a list of line and a list of data(as they are beams. this data represent beam section size). If I join the part I dont know how I should rearrange the data with the lines.(I use python in grasshopper by the way).I want to keep it parametric
Here’s a sample that should help. The sample has no “tolerance” in comparing end points which is something you may need to account for (this can be done by checking distance between points instead of direct equality)
import rhinoscriptsyntax as rs
import Rhino.Geometry.Line as Line
original = [Line(1,2,4,3,5,0), Line(0,0,0,3,5,0), Line(10,0,1,10,10,10), Line(1,2,4,10,10,10)]
original_indices = [i for i in range(len(original))]
connected = [original_indices[0]]
start = original[0].From
end = original[0].To
original_indices.pop(0)
while original_indices:
found_connection = False
for i, index in enumerate(original_indices):
line = original[index]
if start==line.From or start==line.To:
connected.insert(0, index)
original_indices.pop(i)
found_connection = True
if start==line.From: start = line.To
else: start = line.From
elif end==line.From or end==line.To:
connected.append(index)
original_indices.pop(i)
found_connection = True
if end==line.From: end = line.To
else: end = line.From
if not found_connection:
break
for line in original:
rs.AddLine(line.From, line.To)
for i, index in enumerate(connected):
line = original[index]
mid = line.PointAt(0.5)
rs.AddTextDot(str(i), mid)
Let me know you you have any questions