Importing Feature Lines from Civil3D into Dynamo using Python


I have just started using Dynamo and learning Python. I would like to import “Feature Lines” from Civil 3D into Dynamo but I don’t think there is a node for that. Having said that, I think the best way forward is to import using Python. I have written a code based on a video I have watched online. The code is as shown:

import sys
import clr
from Autodesk.DesignScript.Geometry import *
import Autodesk
app2 = Autodesk.AutoCAD.ApplicationServices
om = Autodesk.AutoCAD.DatabaseServices.OpenMode
ts = Autodesk.AutoCAD.DatabaseServices.Transaction
ed = app2.Application.DocumentManager.MdiActiveDocument.Editor
import Autodesk
app = Autodesk.Civil.ApplicationServices
doc = app.CivilApplication.ActiveDocument
ts1 = app2.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()

Import feature line from Civil 3D into Dynamo???

OUT = FeatureLine

Unfortunately, I am unable to post the dynamo file online as I am a new user. Could anyone help me with this? Thank you.


I am also trying to perform the same task, using the default nodes you can extract a corridors feature lines but not a feature line directly.

@Clive_Owen, please have a look at this example I’ve put together, it takes the Land Feature Lines from Sites and not and converts them into PolyCurves. GetLandFeatureLines.dyn (5.8 KB)


Copyright 2019 Autodesk, Inc. All rights reserved.

This file is part of the Civil 3D Python Module.

author = ‘Paolo Emilio Serra’
copyright = ‘2019’
version = ‘1.0.0’

def get_featurelines():
Extract the Land Feature Lines in the document and converts them into Dynamo PolyCurves
:returns: Dynamo PolyCurves

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)
			fls = []
			for oid in btr:
				fl = t.GetObject(oid, OpenMode.ForRead)
				if isinstance(fl, FeatureLine) and fl.SiteId == ObjectId.Null:
					pts = []
					for pt in fl.GetPoints(FeatureLinePointType.AllPoints):
						pts.append(DS.Point.ByCoordinates(pt.X, pt.Y, pt.Z))
					if len(pts) > 1:
			if len(fls) > 0:
			for sid in cdoc.GetSiteIds():
				site = t.GetObject(sid, OpenMode.ForRead)
				fls = []
				for fid in site.GetFeatureLineIds():
					fl = t.GetObject(fid, OpenMode.ForRead)
					pts = []
					for pt in fl.GetPoints(FeatureLinePointType.AllPoints):
						pts.append(DS.Point.ByCoordinates(pt.X, pt.Y, pt.Z))
					if len(pts) > 1:
				if len(fls) > 0:
return output

Thank you Paolo, I shall test this tonight.

Hi Paolo! Thanks for the response! I have tried creating a Feature Line and assigning it to a site. However, I am still unable to extract out the FL into Dynamo. I am not sure if I am doing anything wrong.

1 Like

Hi Paolo! I have figured out the problem. For some reasons, I have to make changes to the python script (e.g. insert/delete an empty line) and save the changes each time I want to run the script. Not sure if it’s a bug or something else. Thank you!

@arthursmmun, no bugs here :slight_smile:
This is how Dynamo works, if a node, any node, has no updated input it will not take part to the execution next time you run the graph.
If you think about it is a smart move: it calculates only the portion of the graph that actually needs to be updated, you just need to know the rules of the game :slight_smile:

In this case you could have simply pressed on the plus/minus buttons on the Python Script node to change its state and force it to recalculate the results.

Please try the following, set the run mode to Automatic, assume you have no Feature Lines in the document, the Python node will return, correctly, Empty List.
In Civil 3D you add a Feature Line with no Site assigned, nothing changes in Dynamo, you click on the plus sign, the node now returns one Feature Line under the List of unassigned Feature Lines.
Then in Civil 3D you create a Feature Line to a Site, nothing changes in Dynamo, you click on the minus sign, now the code returns two Feature Lines under a different grouping.

You can of course also edit the script as you said but you don’t need to save the changes you can just run it from the Python editor.
The method you are using is necessary only when you are making changes to an external module and you want to force Python to reload it.


Hi Paolo,

Great work, thanks.

Is it possible to only have the Feature Lines as output from the node, so I can alter the elevations of the points in another (python) node?
Or do I have to alter the elevations of the points in one single Python node?

What I would like to do is to alter several FLs their elevation points with elevations extracted from a TIN surface.

With your Python node I can create Polyline3D objects from FLs with elevations extracted from a TIN surface already. But I would like to do this with FLs only, without doing a ‘conversion’ to Polylines and without doing this in one single Node. Or should I…?


@lapis you can do it via the same Python script node, what it currently does is merely selecting the right objects in the document. I’m not sure how you want to edit the elevations though, that is the key for the automation you are asking. A tip, think how do you specify the inputs, how do you want to process them and hot the output should look like when it is correct. Put it on paper, use Dynamo nodes if you need to show a workflow diagram and then you can find the logic in Python to do what you have in mind.


Hi @Paolo_Emilio_Serra1, I tried the script on a Land Feature Line containing curves but Dynamo is not converting them correct. I only get the original vertex points without the curves. Any solution to this yet?

Below an example:

Hi yes it doesn’t consider arcs as you can understand from the code it takes only the FL points.

This works well, but I’m looking for help modifying the python script so it only brings in a selection set of feature lines. I don’t want every feature line in the drawing. For instance, I am using the ObjectByProperty node to select feature lines with a specific property set property. I only want to bring these features lines into Dynamo.

Will the coming Civil3DToolkit have anything in there to get the correct geometry in Dynamo?

Can we also get Autocad geometry onto Dynamo, data/values of pre-defined blocks attributes block?


1 Like


Thats a bunch of Feature Line nodes. Cool! :partying_face:

How to I get access to Civil3D Toolkit, I am searching for packages but can’t find it.
Is that a new package to be released?

I was developing my own Zero Touch Nodes in C# but now I rather wait till your library is public :slight_smile: :+1: