Add Profile View Station Elevation Labels

Hi All,

Is it possible to automatic add/place Civil 3D “Add Station Elevation Label on Profile”?

for example, I have AutoCAD block place (random) along alignment. and I would like to add"Add Station Elevation Label on Profile" to show setout information e.g. station, northing, easting, elevation.

18. Dien chenh cao Profiles.dyn (341.4 KB)

Hi @lebinhx3c2012 ,

I’m not aware of any packages that would do this, so we need to use the methods available in the API. Here’s some Python code to try (it’s a bit verbose - sorry). This will create labels and override text components for offset, northing, and easting (since those aren’t available to add to a text component by default).

StaElevLabelsExample.dwg (1.1 MB)
StaElevLabelsExample.dyn (76.9 KB)


import clr

# Add Assemblies for AutoCAD and Civil3D

# Import references from AutoCAD
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
from Autodesk.Civil.DatabaseServices.Styles import *

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
civdoc = CivilApplication.ActiveDocument

# Node inputs
profileView = IN[0]
labelStyleName = IN[1]
markerStyleName = IN[2]
sta = IN[3]
elev = IN[4]
offsetCompName = IN[5]
northingCompName = IN[6]
eastingCompName = IN[7]
offsetCompVal = IN[8]
northingCompVal = IN[9]
eastingCompVal = IN[10]

result = []

if not isinstance(sta, list):
	sta = [sta]
if not isinstance(elev, list):
	elev = [elev]
if not isinstance(offsetCompVal, list):
	offsetCompVal = [offsetCompVal]
if not isinstance(northingCompVal, list):
	northingCompVal = [northingCompVal]
if not isinstance(eastingCompVal, list):
	eastingCompVal = [eastingCompVal]

def create_station_elevation_label(profileView,styleName,markerStyleName,sta,elev):
	global adoc
	global editor
	global civdoc

	with adoc.LockDocument():
	    with adoc.Database as db:
	        with db.TransactionManager.StartTransaction() as t:
				# Get profile view ID
				profileViewId = profileView.InternalObjectId
				# Get label style ID
				labelStyleId = civdoc.Styles.LabelStyles.ProfileViewLabelStyles.StationElevationLabelStyles[styleName]
				# Get market style ID
				markerStyleId = civdoc.Styles.MarkerStyles[markerStyleName]
				# Create label
				label = StationElevationLabel.Create(profileViewId,labelStyleId,markerStyleId,sta,elev)
	return label

def set_label_component(labelId,compName,value):
	global adoc
	global editor
	global civdoc
	with adoc.LockDocument():
	    with adoc.Database as db:
	        with db.TransactionManager.StartTransaction() as t:
				label = t.GetObject(labelId,OpenMode.ForWrite)
				# Get text components
				comps = label.GetTextComponentIds()
				for id in comps:
					comp = t.GetObject(id, OpenMode.ForWrite)
				compId = comps[names.index(compName)]
	return label

for i in range(len(sta)):
		label = create_station_elevation_label(profileView,labelStyleName,markerStyleName,sta[i],elev[i])
OUT = result

@mzjensen, Thank you for so much knowledge on this forum. Could this be a base for labeling other Civil 3D objects like Pipe Networks? The Labeling of C3D Objects via Dynamo has always alluded me. I can get them all set up but the ‘label C3D Object’ node is what I’m missing.

I am actually almost finished with a new package that will allow you to do this. Stay tuned…


@lebinhx3c2012 check out Camber, my new package for Civil 3D. There are some nodes for creating Profile View labels.


1 Like