Profile from polyline (but with a twist)

import sys
import clr

# Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('System.Windows.Forms')
clr.AddReference('Civil3DNodes')

# Create an alias to the Autodesk.AutoCAD.ApplicationServices.Application class
import Autodesk.AutoCAD.ApplicationServices.Application as acapp

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references for Civil 3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

adoc = acapp.DocumentManager.MdiActiveDocument
ed = adoc.Editor
civdoc = CivilApplication.ActiveDocument



Pipe = IN[0]
Pipe1 = IN[1]

PROFILE_VIEW = IN[2]




def move_labels(ids,Pipe1,PROFILE_VIEW):
	if not hasattr(PROFILE_VIEW, "__iter__"):
		PROFILE_VIEW = [PROFILE_VIEW]
		
	if not hasattr(Pipe1, "__iter__"):
		Pipe1 = [Pipe1]
		

	if not hasattr(ids, "__iter__"):
		ids = [ids]
	error_report = None
	res = []
	try:
		with adoc.LockDocument():		
		    with adoc.Database as db:		
		        with db.TransactionManager.StartTransaction() as t:		    
		            sampleLineId = PROFILE_VIEW[0].InternalObjectId
		            objVIEW = t.GetObject(sampleLineId, OpenMode.ForWrite)
		            c = len(IN[1])-1
		            for i in range(c):
		                
		                startpo = Point2d(ids[i], Pipe1[i])
		                endpo = Point2d(ids[i+1], Pipe1[i+1])
		                Entitiesq= objVIEW.Entities.AddFixedTangent(startpo, endpo)
		                res.append(Entitiesq)
		            t.Commit()
	except:
		import traceback
		error_report = traceback.format_exc()
	if error_report is None:
		return res    
	else:
		return error_report



OUT = move_labels(Pipe,Pipe1,PROFILE_VIEW)

1 Like