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)
Thanks,

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)

StaElevLabels

import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')

# 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)
				t.Commit()
	return label

def set_label_component(labelId,compName,value):
	
	global adoc
	global editor
	global civdoc
	
	names=[]
	
	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)
					names.append(comp.General.Name)
				compId = comps[names.index(compName)]
				label.SetTextComponentOverride(compId,value)
				t.Commit()
	return label

for i in range(len(sta)):
		label = create_station_elevation_label(profileView,labelStyleName,markerStyleName,sta[i],elev[i])
		set_label_component(label,offsetCompName,offsetCompVal[i])
		set_label_component(label,northingCompName,northingCompVal[i])
		result.append(set_label_component(label,eastingCompName,eastingCompVal[i]))
		
OUT = result
4 Likes

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

4 Likes

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

PVLabels

2 Likes

These are such great tools for the Camber kit! Thank you for adding these. Is there any chance you will build a version for profile lablels soon (e.g. major/minor station, lines, grade breaks)? And if you know of any other tools you have come across that make adding labels to many profiles across many alignments go faster your expertise would be much appreciated.

I do not have plans for that at the moment because it is rather involved. The API makes it easy to add a label set when the profile is originally created, but doing it after the fact in a separate step is more difficult. You basically have to create each and every label individually. It’s something that I’ve thought about before but I just don’t have time for it now. Sorry.

1 Like

Thank you for the response and for all the work you have put into the Camber package. I especially like the dropdown menus you have built with many of the drawing features.

This is just a FYI for you mzjensen, but I am hoping some other users might stumble across this and find it useful. I was only able to make it using a bunch of pieces of others’ scripts from this forum…

With a few of the other tools you have put together I was able to pack together a slightly awkward but still useful workaround for adding similar or identical labels to many alignments in profile view. We currently have a project with over 200 profile views (which keep changing, of course) so this really saved us some time.
AddSurfaceProfile-GENERAL.dyn (64.4 KB)
This .dyn called AddSurfaceProfile-GENERAL will project a profile to all alignments in your current drawing.

Add Label - GENERAL.dyn (64.6 KB)

Add Label - GENERAL then projects a style to a profile having the name of a surface in your drawing. We can sneak around needing to attribute a source surface by the default that C3D uses the surface name in all the profile names. The script filters out alignments with null values for stationing (where you don’t need labels) and sends a modified station-elevation label to the vertical and horizontal position on the alignment as assigned by the corresponding surface. With this approach, the user still needs to make a station-elevation label style for each profile label they want (I have just been using 1 style per surface type - some with elevations shown too and some without). The .dyn script I attached will pull a label for your one set of inputs, so I just copy/pasted as many as I needed to shoot labels all through my .dwg to exactly the correct position on my alignments. This isn’t as good as a true profile label, since it can’t pull attributes of the profile (like description) easily, but was a convenient workaround. I am sure others could streamline some of this, but hopefully this can save someone else a little time if they are in the same position my team was a couple weeks ago.

Thanks again!

2 Likes


Image included to show a single instance of the label projection, then another that probably isn’t readable but shows the copy/paste approach for sending labels to many surfaces across all your profiles.

Thanks for sharing, @dforrestMJRCQ!

Hi, why I can’t run your script? There is a problem of indentation?

Thank you

@User3 I would recommend using the nodes available in the Camber package if they meet your requirements. See above post.

Yes I’ve already saw the Camber Package, but I’m trying to add another type of labels (not depth or station elevation like camber package), so I’m trying to adapt the python script to my needs.
Why I can’t run your script?
Thank you

What type of label are you interested in adding?

My intention is to add labels from an excel to the profile view in some stations of a profile that I want. I also wanted to add a block near to the label.
I don’t know if it is possible to do

I believe those would be profile view station elevation labels, right?

No, for example structures, like bridges imported from infraworks and plotted in the profile view or other type of civil structures.
In other words, I want to do the same think that do the dynamo script “add annotation along alignment” that Autodesk made for civil 3D, but not in planimetry but in profile view.

A profile view station elevation label can contain any information that you want, so I think it will work for your requirements. But in case I’m mistaken, can you share an example screenshot or DWG showing your end goal?

Image 3
Image 2
BridgeAnnotatedAlongAlignment.xlsx (9.7 KB)

For example, I had this two bridges along an alignment, the first one imported from revit and the second one from infraworks, and others civil structures plotted in profile view.

My goal is add labels imported from an excel, in a station that I want (written in the excel) in which there is written: Bridge A, Bridge B, for example.

Maybe I wanted also to attach a block that rappresent a bridge that I call from model space.

Hi Zachri

Maybe you wanted a dwg file, I am attaching it.

However I attach also an image that explain what kind of node I sayd.

Maybe you can do something in your Camber Package.

Thank you.

Bridge.dwg (4.6 MB)