FeatureLine to Polyline 2D

@kovacsv this is close but isn’t quite correct for Feature Line arc segments because the FeatureLine.PolyCurve node tessellates the curves to create an approximation. The “pure” way to do it would be to recreate the segments from the bulge values.

FeatureLineBaseCurve

import clr

clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

from Autodesk.Civil.DatabaseServices import *
from Autodesk.Civil import *

def extract_basecurve(featureLines):
	
	output=[]
	obj=[]
	
	if not featureLines:
		return
	
	if not isinstance(featureLines,list):
		featureLines = [featureLines]
	
	adoc = Application.DocumentManager.MdiActiveDocument
	
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				for featureLine in featureLines:
					obj = featureLine.InternalDBObject
					if isinstance(obj, FeatureLine):
						# Get bulge values
						bulges=[]
						for i in range(0,obj.PointsCount-1):
							bulges.Add(obj.GetBulge(i))
						bulges.append(0)
						
						# Get all points
						pntsAll=obj.GetPoints(FeatureLinePointType.AllPoints)
						lstPntsAll=[]
						for i in pntsAll:
							lstPntsAll.append(Point2d(i.X,i.Y))
							
						# Get PI points
						pntsPI=obj.GetPoints(FeatureLinePointType.PIPoint)
						lstPntsPI=[]
						for j in pntsPI:
							lstPntsPI.append(Point2d(j.X,j.Y))
						
						# Get indices of PI points
						index=[]
						for pt in lstPntsPI:
							index.append(lstPntsAll.index(pt))
						
						# Create filtered list of bulge values
						filterBulge=[]
						for k in index:
							filterBulge.append(bulges[k])							
						
						# Polyline constructor
						pl = Polyline()
						bt = t.GetObject(db.BlockTableId, OpenMode.ForRead)
						btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
						
						# Add vertices
						for l in range(0,len(lstPntsPI)):
							pl.AddVertexAt(l,lstPntsPI[l],filterBulge[l],0,0)
						
						# Add entity to database
						btr.AppendEntity(pl)
						t.AddNewlyCreatedDBObject(pl, True)
						output.append(pl)						
				t.Commit()			
		return output
	
OUT = extract_basecurve(IN[0])
4 Likes