Loop while CodeBlock

So I have a list of curves in Dynamo Studio that were imported from Civil3D. The Civil3D drawing had a bunch of building pads as lines and arcs. When they were imported into Dynamo Studio, these lines and arcs were disorganized. I want to recreate the building pads in Dynamo Studio by getting the four corner points of each building pads(startpoints/endpoints of the lines/arcs) and creating a polygon from those four points. Everytime I run my code, it says run started and it never finishes. Am I stuck in a loop? HELP PLEASE.

Here is My Code:

def SortLists(BP:var[])
{
Lots = {};
return = [Imperative]
{
cnt = List.Count(BP);
while (cnt > 0)
{
Lot = {};
StartPt = BP[0].StartPoint;
EndPt = BP[0].EndPoint;
Lot = List.AddItemToEnd(StartPt,Lot);
OccupiedPt = StartPt;
BP = List.RemoveItemAtIndex(BP, 0);
cnt = List.Count(BP);
while (OccupiedPt != EndPt)
{
i = 0;
while (i < cnt)
{
sp = BP[i].StartPoint;
ep = BP[i].EndPoint;
if (sp == OccupiedPt)
{
Lot = List.AddItemToEnd(ep, Lot);
OccupiedPt = ep;
BP = List.RemoveItemAtIndex(BP, i);
cnt = List.Count(BP);
i = cnt;
}
elseif (ep == OccupiedPt)
{
Lot = List.AddItemToEnd(sp, Lot);
OccupiedPt = sp;
BP = List.RemoveItemAtIndex(BP, i);
cnt = List.Count(BP);
i = cnt;
}
}
}
pg = Polygon.ByPoints(Lot);
Lots = List.AddItemToEnd(pg, Lots);
}
return = cnt;
}
};
SortLists(curves);

Are you trying to group your curves you can try the Group Curves node in the Archi-lab package. It’s basically a Python script.

#Copyright(c) 2015, Konrad Sobon
# @arch_laboratory, http://archi-lab.net

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

inputCurves = IN[0]

#join/group curves function
def groupCurves(Line_List): 
	ignore_distance = 0.1 # Assume points this close or closer to each other are touching 
	Grouped_Lines = [] 
	Queue = set() 
	while Line_List: 
		Shape = [] 
		Queue.add(Line_List.pop()) # Move a line from the Line_List to our queue 
		while Queue: 
			Current_Line = Queue.pop() 
			Shape.append(Current_Line) 
			for Potential_Match in Line_List: 
				Points = (Potential_Match.StartPoint, Potential_Match.EndPoint)
				for P1 in Points: 
					for P2 in (Current_Line.StartPoint, Current_Line.EndPoint): 
						distance = P1.DistanceTo(P2) 
						if distance <= ignore_distance: 
							Queue.add(Potential_Match) 
			Line_List = [item for item in Line_List if item not in Queue]
		Grouped_Lines.append(Shape) 
	return Grouped_Lines

OUT = groupCurves(inputCurves)
1 Like

I want help on my code. I want to know why it isn’t working