Skip to content

Instantly share code, notes, and snippets.

@ksobon
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksobon/5000cdc0c54adaefc46f to your computer and use it in GitHub Desktop.
Save ksobon/5000cdc0c54adaefc46f to your computer and use it in GitHub Desktop.
groupCurves
#Copyright(c) 2015, Konrad Sobon
# @arch_laboratory, http://archi-lab.net
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
from System.Collections.Generic import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment