join curve revit api
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
#from Revit import GeometryConversion as gp
import math
curves = IN[0]
#The next 2 methods will assume that the directions is known.
#The start point of a curve
def startPoint(curve):
return curve.GetEndPoint(0)
#The end point of a curve
def endPoint(curve):
return curve.GetEndPoint(1)
#Groups lines to be joined in sublists with the curves that have to be joined
def joinCurves(list):
comp=[]
re=[]
unjoined = []
for c in curves:
c = c.ToRevitType()
match = False
for co in comp:
if startPoint(c).IsAlmostEqualTo(startPoint(co)) and endPoint(c).IsAlmostEqualTo(endPoint(co)):
match = True
if match:
continue
else:
comp.append(c)
joined = []
for c2 in curves:
match = False
c2 = c2.ToRevitType()
for co in comp:
if startPoint(c2).IsAlmostEqualTo(startPoint(co)) and endPoint(c2).IsAlmostEqualTo(endPoint(co)):
match = True
if match:
continue
else:
if c2.Intersect(c) == SetComparisonResult.Disjoint:
continue
elif c2.Intersect(c) == SetComparisonResult.Equal:
continue
elif c2.Intersect(c) == SetComparisonResult.Subset:
comp.append(c2)
joined.append(c2.ToProtoType())
joined.append(c.ToProtoType())
re.append(joined)
return re
result = joinCurves(curves)
OUT = result