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