# Creating CogoPoints with Python Script

**URL:** <https://forum.dynamobim.com/t/creating-cogopoints-with-python-script/65461>\
**Category:** Civil 3D\
**Created:** [June 23, 2021, 1:58pm UTC](https://forum.dynamobim.com/t/creating-cogopoints-with-python-script/65461 "2021-06-23T13:58:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hosneyalaa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/hosneyalaa/32/100865_2.png) [@hosneyalaa](https://forum.dynamobim.com/u/hosneyalaa)\
**Post date:** [June 23, 2021, 1:58pm UTC](https://forum.dynamobim.com/t/creating-cogopoints-with-python-script/65461/1 "2021-06-23T13:58:11Z")

</div>

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?

```auto

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('ProtoGeometry')

# 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 )
					
						t.Commit		
	
	#return output
	
OUT = get_CogoPoints()

```

![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/2/f2acc7bf71ac9182a3fb43a448b43462767a97e0.jpeg)  
[feature line to points.dwg](https://forum.dynamobim.com/uploads/short-url/xVLlSJluF5Z2rBed2563r8hZiL6.dwg) (941.8 KB)

thanks  
advance

---

<div class="post-metadata">

**Author:** ![mzjensen](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@mzjensen](https://forum.dynamobim.com/u/mzjensen)\
**Post date:** [June 23, 2021, 2:06pm UTC](https://forum.dynamobim.com/t/creating-cogopoints-with-python-script/65461/2 "2021-06-23T14:06:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hosneyalaa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/hosneyalaa/32/100865_2.png) [@hosneyalaa](https://forum.dynamobim.com/u/hosneyalaa)\
**Post date:** [June 23, 2021, 3:15pm UTC](https://forum.dynamobim.com/t/creating-cogopoints-with-python-script/65461/3 "2021-06-23T15:15:09Z")

</div>

@zachri.jensen  
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

---

<div class="post-metadata">

**Author:** ![Assem.Daaboul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/assem.daaboul/32/116900_2.png) [@Assem.Daaboul](https://forum.dynamobim.com/u/Assem.Daaboul)\
**Post date:** [June 24, 2021, 7:53am UTC](https://forum.dynamobim.com/t/creating-cogopoints-with-python-script/65461/4 "2021-06-24T07:53:45Z")

</div>

Hi @hosneyalaa,  
I agree with @zachri.jensen, using dynamo nodes in dynamo sounds more logical in your case. Check this [link](https://primer.dynamobim.org/13_Best-Practice/13-1_Introduction.html) 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](https://forum.dynamobim.com/uploads/short-url/nFbA9QnjVz4KXJZLVVE1CNatvjd.dyn) (4.2 KB)

---

<div class="post-metadata">

**Author:** ![hosneyalaa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/hosneyalaa/32/100865_2.png) [@hosneyalaa](https://forum.dynamobim.com/u/hosneyalaa)\
**Post date:** [June 24, 2021, 8:20am UTC](https://forum.dynamobim.com/t/creating-cogopoints-with-python-script/65461/5 "2021-06-24T08:20:39Z")

</div>

> [@hosneyalaa](#):
>
> Thank you for the codes you shared

Thank you for HELPE
