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