# 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. #Input surface from the file dataEnteringNode = IN[0] #Input the interval of the color banding interval = IN[1] #Input a survey precision or "play", should be shown in lidar metadata surveyprecision = IN[2] 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: 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 #Getting maximum and minimum elevations of the surface gp = surface.GetGeneralProperties() minel = gp.MinimumElevation maxel = gp.MaximumElevation minelf = int(minel) maxelc = int(maxel) minelfn = int(minelf) maxelcn = int(maxelc) #Defining area near 0 for different color banding according to survey precsision upperprecision = 0 + surveyprecision lowerprecision = 0 - surveyprecision saed = [] #Number of color stepping in the red and green redsteps = int(((lowerprecision - minelf) / interval)+1) greensteps = int(((maxelc - upperprecision) / interval)+1) i = 0 n = 0 upperbound = 0 #Defining a list of lists to export to excel table = [] #Defining the red color stepping below 0 for cut while upperbound >= minelf: lowerbound = lowerprecision - interval - i upperbound = lowerbound+interval g = ((250/redsteps)*n) b = ((250/redsteps)*n) saed.append(SurfaceAnalysisElevationData(lowerbound, upperbound, Color.FromRgb(250,g,b))) i += interval n += 1 table.append([int(lowerbound),int(upperbound),250,g,b]) #Areas that aren't cut will be fill else: i = 0 n = 0 while lowerbound <= maxelc: lowerbound = upperprecision + i upperbound = lowerbound + interval r = ((250/greensteps)*n) b = ((250/greensteps)*n) saed.append(SurfaceAnalysisElevationData(lowerbound, upperbound, Color.FromRgb(r,250,b))) i += interval n += 1 table.append([int(lowerbound),int(upperbound),r,250,b]) #Appending cut play close to 0 saed.append(SurfaceAnalysisElevationData(lowerprecision, 0, Color.FromRgb(255,190,92))) table.append([int(lowerprecision),0,255,190,92]) #Appending fill play close to 0 saed.append(SurfaceAnalysisElevationData(0, upperprecision, Color.FromRgb(236,247,29))) table.append([0,int(upperprecision),263,247,29]) #Sorting the list of lists to be used as a legend sorttable = table.sort() surface.Analysis.SetElevationData(Array[SurfaceAnalysisElevationData](saed)) # Commit before end transaction t.Commit() return table # Assign your output to the OUT variable. OUT = set_surface_analysis(IN[0])