Surface Spot Elevation At Point (Civil3D)

I’m attempting to place surface spot elevation labels in Civil 3D based off of the selected geometry (using vertices). Right now I have it set up for a single point, just testing… However, I’m getting an error (shown in the image) that indicates that ObjectId is being passed, not Point2d. Need some help figuring out where I’ve gone astray, which I imagine is somewhere within the calls for the Spot Elevation style.


SetSurfaceLabels.dyn (9.2 KB)

import clr

clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('ProtoGeometry')

from Autodesk.DesignScript.Geometry import *

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
from Autodesk.Civil.DatabaseServices.Styles import *

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

surface = IN[0]
labelStyleName = IN[1]
markerStyleName = IN[2]
points = IN[3]

def create_surface_elev_label(surface,labelStyleName,markerStyleName,points):

	global adoc
	global civdoc
	
	output = []
	
	if not isinstance(points, list):
		points = [points]

	with adoc.LockDocument():
	    with adoc.Database as db:
	        with db.TransactionManager.StartTransaction() as t:
				surfaceId = surface.InternalObjectId
				obj = t.GetObject(surfaceId, OpenMode.ForRead)
				if isinstance(obj, Surface):
					# Get label style ID
					labelStyleId = civdoc.Styles.LabelStyles.SurfaceLabelStyles.SpotElevationLabelStyles[labelStyleName]
					# Get marker style ID
					markerStyleId = civdoc.Styles.MarkerStyles[markerStyleName]
					# Create Point2d from ProtoGeometry point
					for point in points:
						location = Point2d(point.X,point.Y)
						# Create label
						label = SurfaceElevationLabel.Create(surfaceId,labelStyleId,markerStyleId,location)
						output.append(t.GetObject(label,OpenMode.ForRead))
				t.Commit()
	return output

OUT = create_surface_elev_label(IN[0],IN[1],IN[2],IN[3])

In picture
Add in[3] to node python

1 Like

Ridiculous… I just saw it as I was reviewing my post. I added it back in, but I do get an error besides this embarrassing one.
SetSurfaceLabels.dyn (9.2 KB)
RampTest - Copy.dwg (3.3 MB)
Geez

Try
Python 2.7 no python 3

And
Try
label =SurfaceElevationLabel.Create(surfaceId,location)

For find error

1 Like

The arguments for SurfaceElevationLabel.Create are in the wrong order. The Point2d should be second.

2 Likes

Welcome @cole.fritz
If you can attach the solution to this the problem Thanks

1 Like

That’s the one! You’re a godsend, @mzjensen. (Thanks @hosneyalaa you helped out big time as well).
Here it is.
SetSurfaceLabels.dyn (9.2 KB)

1 Like