Creating CogoPoints with Python Script

Hello all
I’m trying to creating CogoPoints on a FeatureLines
with Python Script , but there is an error
Can someone help me where is the problem?

import clr

# Add Assemblies for AutoCAD and Civil 3D APIs

# Add standard Python references
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import os
import math

# Add references to manage arrays, collections and interact with the user
from System import *
from System.IO import *
from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox

# 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 PropertySets
from Autodesk.Aec.PropertyData import *
from Autodesk.Aec.PropertyData.DatabaseServices import *

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

# Import Dynamo Geometry reference
import Autodesk.DesignScript.Geometry as DS

adoc = acapp.DocumentManager.MdiActiveDocument
cdoc = CivilApplication.ActiveDocument
ed = adoc.Editor
#cogoPointss = cdoc.CogoPoints

def get_CogoPoints():
	global adoc
	global cdoc
	output = []

	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
				btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
				for sid in cdoc.GetSiteIds():
					site = t.GetObject(sid, OpenMode.ForRead)
					for fid in site.GetFeatureLineIds():
						fl = t.GetObject(fid, OpenMode.ForRead)
					    for pt in fl.GetPoints(FeatureLinePointType.AllPoints):
						    oid = cdoc.CogoPoints.Add(Point3d(pt.X, pt.Y, pt.Z),True )
	#return output
OUT = get_CogoPoints()

feature line to points.dwg (941.8 KB)


Hi @hosneyalaa,

I didn’t look at the code too closely, but I’m curious if there is a particular reason why you’re using this approach instead of the Civil 3D Toolkit (for the Feature Line data) and the OOTB nodes for COGO points?

I have knowledge of using API WITH C# language
I am trying to implement API in python
Thank you for the codes you shared
and all members

please help me

Hi @hosneyalaa,
I agree with @mzjensen, using dynamo nodes in dynamo sounds more logical in your case. Check this link in Dynamo Primer about best practices.

However, and to answer your question; below is a script that adds cogo points at featureline vertices.
FeaturelinePoints.dyn (4.2 KB)

1 Like

Thank you for HELPE