Civil 3D 2013新API -- 建立空間幾何點(COGO Point)

weixin_34219944發表於2012-07-25

Civil 3D 2013 .net API中新引入了空間幾何點相關的API,我們可以建立、修改、刪除空間幾何點。 類CogoPointCollection表示所有空間幾何點的集合,這個類可以通過CivilApplication.ActiveDocument.CogoPoints得到。建立新的COGOPoint,呼叫CogoPointCollection.Add()方法即可。下面是一個程式碼片段:

 

    [CommandMethod("CreateCOGOPoint")]
    public void CreateCOGOPoint()
    {
      Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
      Database db = ed.Document.Database;
      CivilDocument civilDoc = CivilApplication.ActiveDocument;
      
      // Select the location for COGO Point
      PromptPointOptions ppo = new PromptPointOptions("\nSelect the location to Create a COGO Point :");
      PromptPointResult ppr = ed.GetPoint(ppo);

      if (ppr.Status != PromptStatus.OK)
        return;
      Point3d location = ppr.Value;

      //start a transaction
      using (Transaction trans = db.TransactionManager.StartTransaction())
      {

        // All points in a document are held in a CogoPointCollection object
        // We can access CogoPointCollection through the CivilDocument.CogoPoints property

        CogoPointCollection cogoPoints = CivilApplication.ActiveDocument.CogoPoints;

        // Adds a new CogoPoint at the given location with the specified description information
        ObjectId pointId = cogoPoints.Add(location, "Survey Point");
        CogoPoint cogoPoint = pointId.GetObject(OpenMode.ForWrite) as CogoPoint;

        // Set Some Properties
        cogoPoint.PointName = "Survey_Base_Point";
        cogoPoint.RawDescription = "This is Survey Base Point";

        trans.Commit();

      }
    }

執行結果:

image

相關文章