# 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. dataEnteringNode = IN adoc = Application.DocumentManager.MdiActiveDocument cdoc = CivilApplication.ActiveDocument editor = adoc.Editor def set_surface_analysis(surface_name): global adoc global cdoc with adoc.LockDocument(): with adoc.Database as db: with db.TransactionManager.StartTransaction() as t: # Place your code below # # bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite) btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) surface = None for oid in cdoc.GetSurfaceIds(): obj = t.GetObject(oid, OpenMode.ForRead) if obj.Name == surface_name: surface = obj break if surface is None: return False gp = surface.GetGeneralProperties() minel = gp.MinimumElevation maxel = gp.MaximumElevation minelf = minel - (minel - (math.floor(minel / .5) * .5)) maxelc = ((math.ceil(maxel / .5) * .5) - maxel) + maxel minelfn = int(minelf) maxelcn = int(maxelc) saed = [] interval = .5 steps = int((maxelc - minelf) / .5) if steps is not None: a = 200 / steps for i in range(0, steps, int(interval * 2)): saed.append(SurfaceAnalysisElevationData(minelf + ((interval) * i), minelf + ((interval) * (i + 1)), Color.FromRgb(255, i * a, i * a))) surface.Analysis.SetElevationData(Array[SurfaceAnalysisElevationData](saed)) # Commit before end transaction t.Commit() return True # Assign your output to the OUT variable. OUT = set_surface_analysis(IN[0])