Checked:
Improved Python Script for Dynamo – Get Min/Max Elevation from Multiple Surfaces
Versión en Inglés
I’ve modified the script to directly accept TinSurface objects in Civil 3D 2026, allowing it to read the minimum and maximum elevations from two surfaces. The logic can be easily expanded to support a list of surfaces.
Feel free to reach out with any feedback or questions!
Versión en Español
He adaptado el script para que reconozca directamente dos superficies (objetos TinSurface) en Civil 3D 2026 y obtenga automáticamente las elevaciones mínima y máxima de esos objetos. Aunque en este caso son dos, puede ampliarse fácilmente para aceptar una lista completa de superficies.
Quedo atento a cualquier comentario o duda.
Mi LinkedIn : https://www.linkedin.com/in/brian-mendoza-márquez-95976a227/
# Load the Python Standard and DesignScript Libraries
import sys
import clr
import math
# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
from Autodesk.AutoCAD.Colors import *
from System import Array
# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
# The inputs to this node will be stored as a list in the IN variables.
list_surface_obj = [IN[0], IN[1]] # Ahora IN[0] es la lista de objetos Surface directamente
surveyprecision = 1
adoc = Application.DocumentManager.MdiActiveDocument
cdoc = CivilApplication.ActiveDocument
def get_surface_elevations(list_surface_obj, surveyprecision):
"""
Obtiene la elevación mínima y máxima de una superficie dada.
:param surface_obj: Objeto de superficie de Civil 3D
:return: Lista con [min_elev, max_elev]
"""
try:
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
list_surfaces = []
# Abrir los objetos de superficies
for surface_obj in list_surface_obj:
surface = t.GetObject(surface_obj.InternalObjectId, OpenMode.ForRead)
list_surfaces.append(surface)
list_elevations = []
for surface in list_surfaces:
# Obtener propiedades generales
gp = surface.GetGeneralProperties()
minel = round(gp.MinimumElevation, surveyprecision)
maxel = round(gp.MaximumElevation, surveyprecision)
list_elevations.append(minel)
list_elevations.append(maxel)
t.Commit()
return {"max_elevation": max(list_elevations),"min_elevation": min(list_elevations) }
except Exception as ex:
return ["Error: " + str(ex)]
# Llamada a la función
OUT = get_surface_elevations(list_surface_obj, surveyprecision)
Example Node: