Civil 3D 2013利用API把三角网曲面提取为栅格网
Civil 3D 2013中对曲面的.net API做了增强,可以让我们从三角网曲面中提取栅格网。先看看效果:
下面的代码演示了从一个三角网曲面中提取三维栅格网,这些栅格网是由红色是三维多段线polyline构成的。
// using System; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; using Autodesk.Civil.DatabaseServices; using Autodesk.Civil; // This line is not mandatory, but improves loading performances [assembly: CommandClass(typeof(SurfaceApiInCivil3D2013.MyCommands))] namespace SurfaceApiInCivil3D2013 { // This class is instantiated by AutoCAD for each document when // a command is called by the user the first time in the context // of a given document. In other words, non static data in this class // is implicitly per-document! public class MyCommands { static Document _doc = Application.DocumentManager.MdiActiveDocument; static Editor _editor = _doc.Editor; static Database db = _doc.Database; private ObjectId promptForTinSurface() { PromptEntityOptions options = new PromptEntityOptions( "\nSelect a TIN Surface: "); options.SetRejectMessage( "\nThe selected object is not a TIN Surface."); options.AddAllowedClass(typeof(TinSurface), true); PromptEntityResult result = _editor.GetEntity(options); if (result.Status == PromptStatus.OK) { // Everything is cool; we return the selected // surface ObjectId. return result.ObjectId; } return ObjectId.Null; // Indicating error. } [CommandMethod("CDS_ExtractGrid")] public void CDS_ExtractGrid() { ObjectId surfaceId = promptForTinSurface(); if (surfaceId == ObjectId.Null) { _editor.WriteMessage("\nNo TIN Surface selected."); return; } using (Transaction tr = db.TransactionManager.StartTransaction()) { TinSurface surface = surfaceId.GetObject(OpenMode.ForRead) as TinSurface; ObjectIdCollection ids = surface.ExtractGridded( SurfaceExtractionSettingsType.Model); foreach (ObjectId id in ids) { Polyline3d polyline = id.GetObject(OpenMode.ForWrite) as Polyline3d; if (polyline != null) { using (polyline) { polyline.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0); } } } tr.Commit(); } } } }
想了解更多Civil 3D 2013 API,请看Civilized Development博客中的21WOJP系列 (21 Week Of JayPeak), JayPeak是Civil 3D 2013的代码名。