Civil 3D 2013利用API把三角網曲面提取為柵格網


Civil 3D 2013中對曲面的.net API做了增強,可以讓我們從三角網曲面中提取柵格網。先看看效果:

image

 

下面的代碼演示了從一個三角網曲面中提取三維柵格網,這些柵格網是由紅色是三維多段線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的代碼名。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM