# Importing Feature Lines from Civil3D into Dynamo using Python

**URL:** <https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513>\
**Category:** Civil 3D\
**Created:** [June 24, 2019, 3:33am UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513 "2019-06-24T03:33:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![arthursmmun](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@arthursmmun](https://forum.dynamobim.com/u/arthursmmun)\
**Post date:** [June 24, 2019, 3:33am UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/1 "2019-06-24T03:33:53Z")

</div>

Hi,

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  
clr.AddReference(‘ProtoGeometry’)  
from Autodesk.DesignScript.Geometry import \*  
clr.AddReference(‘acdbmgd’)  
clr.AddReference(‘acmgd’)  
clr.AddReference(‘accoremgd’)  
clr.AddReference(‘AecBaseMgd’)  
import Autodesk  
app2 = Autodesk.AutoCAD.ApplicationServices  
om = Autodesk.AutoCAD.DatabaseServices.OpenMode  
ts = Autodesk.AutoCAD.DatabaseServices.Transaction  
ed = app2.Application.DocumentManager.MdiActiveDocument.Editor  
clr.AddReference(‘AeccDbMgd’)  
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.

---

<div class="post-metadata">

**Author:** ![Clive\_Owen](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Clive\_Owen](https://forum.dynamobim.com/u/Clive_Owen)\
**Post date:** [July 12, 2019, 7:10pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/2 "2019-07-12T19:10:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Paolo\_Emilio\_Serra1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paolo_emilio_serra1/32/12902_2.png) [@Paolo\_Emilio\_Serra1](https://forum.dynamobim.com/u/Paolo_Emilio_Serra1)\
**Post date:** [July 26, 2019, 2:40pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/3 "2019-07-26T14:40:27Z")

</div>

@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](https://forum.dynamobim.com/uploads/short-url/xnN9qtKEc80c6Ns3IJ7Nq2l0RHF.dyn) (5.8 KB)

---

<div class="post-metadata">

**Author:** ![Paolo\_Emilio\_Serra1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paolo_emilio_serra1/32/12902_2.png) [@Paolo\_Emilio\_Serra1](https://forum.dynamobim.com/u/Paolo_Emilio_Serra1)\
**Post date:** [July 26, 2019, 2:52pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/4 "2019-07-26T14:52:29Z")

</div>

“”"  
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:
						fls.append(DS.PolyCurve.ByPoints(pts))
			if len(fls) > 0:
				output.append(fls)
			
			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:
						fls.append(DS.PolyCurve.ByPoints(pts))
				if len(fls) > 0:
					output.append(fls)			
return output
```

---

<div class="post-metadata">

**Author:** ![Clive\_Owen](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Clive\_Owen](https://forum.dynamobim.com/u/Clive_Owen)\
**Post date:** [July 30, 2019, 12:19pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/5 "2019-07-30T12:19:26Z")

</div>

Thank you Paolo, I shall test this tonight.

---

<div class="post-metadata">

**Author:** ![arthursmmun](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@arthursmmun](https://forum.dynamobim.com/u/arthursmmun)\
**Post date:** [July 31, 2019, 1:09am UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/6 "2019-07-31T01:09:43Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/1/715e2a90b75980b0caf6bdbae84cbd2f7d40ebcf.png)

---

<div class="post-metadata">

**Author:** ![arthursmmun](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@arthursmmun](https://forum.dynamobim.com/u/arthursmmun)\
**Post date:** [July 31, 2019, 1:27am UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/7 "2019-07-31T01:27:50Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Paolo\_Emilio\_Serra1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paolo_emilio_serra1/32/12902_2.png) [@Paolo\_Emilio\_Serra1](https://forum.dynamobim.com/u/Paolo_Emilio_Serra1)\
**Post date:** [July 31, 2019, 6:47am UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/8 "2019-07-31T06:47:15Z")

</div>

@arthursmmun, no bugs here 🙂  
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 🙂

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.

---

<div class="post-metadata">

**Author:** ![lapis](https://avatars.discourse-cdn.com/v4/letter/l/a698b9/32.png) [@lapis](https://forum.dynamobim.com/u/lapis)\
**Post date:** [September 14, 2019, 10:46am UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/9 "2019-09-14T10:46:58Z")

</div>

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…?

Edward

---

<div class="post-metadata">

**Author:** ![Paolo\_Emilio\_Serra1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paolo_emilio_serra1/32/12902_2.png) [@Paolo\_Emilio\_Serra1](https://forum.dynamobim.com/u/Paolo_Emilio_Serra1)\
**Post date:** [September 16, 2019, 7:16am UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/10 "2019-09-16T07:16:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![John.DeLeeuw](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/john.deleeuw/32/79337_2.png) [@John.DeLeeuw](https://forum.dynamobim.com/u/John.DeLeeuw)\
**Post date:** [October 1, 2019, 10:00am UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/11 "2019-10-01T10:00:41Z")

</div>

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:

 ![2019-10-01_11-54-35](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/1/a1bd7340c68bd396392ea3616719de61972cecc3.png)

---

<div class="post-metadata">

**Author:** ![Paolo\_Emilio\_Serra1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paolo_emilio_serra1/32/12902_2.png) [@Paolo\_Emilio\_Serra1](https://forum.dynamobim.com/u/Paolo_Emilio_Serra1)\
**Post date:** [October 5, 2019, 4:50pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/12 "2019-10-05T16:50:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![keith.sowinski](https://avatars.discourse-cdn.com/v4/letter/k/d26b3c/32.png) [@keith.sowinski](https://forum.dynamobim.com/u/keith.sowinski)\
**Post date:** [October 22, 2019, 5:24pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/13 "2019-10-22T17:24:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![John.DeLeeuw](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/john.deleeuw/32/79337_2.png) [@John.DeLeeuw](https://forum.dynamobim.com/u/John.DeLeeuw)\
**Post date:** [November 5, 2019, 2:58pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/14 "2019-11-05T14:58:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nivaldo.curcio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nivaldo.curcio/32/83618_2.png) [@nivaldo.curcio](https://forum.dynamobim.com/u/nivaldo.curcio)\
**Post date:** [November 5, 2019, 4:43pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/15 "2019-11-05T16:43:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paolo\_Emilio\_Serra1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paolo_emilio_serra1/32/12902_2.png) [@Paolo\_Emilio\_Serra1](https://forum.dynamobim.com/u/Paolo_Emilio_Serra1)\
**Post date:** [November 5, 2019, 10:36pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/16 "2019-11-05T22:36:34Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![Paolo\_Emilio\_Serra1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paolo_emilio_serra1/32/12902_2.png) [@Paolo\_Emilio\_Serra1](https://forum.dynamobim.com/u/Paolo_Emilio_Serra1)\
**Post date:** [November 6, 2019, 12:44pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/17 "2019-11-06T12:44:36Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/9/4965547b0c75f97f9f9fca2f4a94f258c212231d.png)

---

<div class="post-metadata">

**Author:** ![John.DeLeeuw](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/john.deleeuw/32/79337_2.png) [@John.DeLeeuw](https://forum.dynamobim.com/u/John.DeLeeuw)\
**Post date:** [November 6, 2019, 1:24pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/18 "2019-11-06T13:24:16Z")

</div>

Thats a bunch of Feature Line nodes. Cool! 🥳

---

<div class="post-metadata">

**Author:** ![nivaldo.curcio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nivaldo.curcio/32/83618_2.png) [@nivaldo.curcio](https://forum.dynamobim.com/u/nivaldo.curcio)\
**Post date:** [November 6, 2019, 1:27pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/19 "2019-11-06T13:27:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Anton\_Huizinga](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/anton_huizinga/32/155377_2.png) [@Anton\_Huizinga](https://forum.dynamobim.com/u/Anton_Huizinga)\
**Post date:** [November 6, 2019, 1:39pm UTC](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513/20 "2019-11-06T13:39:11Z")

</div>

I was developing my own Zero Touch Nodes in C# but now I rather wait till your library is public 🙂 👍

[Next page](https://forum.dynamobim.com/t/importing-feature-lines-from-civil3d-into-dynamo-using-python/37513.md?page=2)
