パイプを作成する

パイプ オブジェクトは、パイプ ネットワークの配管を表します。パイプは真っ直ぐなパイプや曲がったパイプを作成するパイプ ネットワークのメソッド、AddLinePipe()AddCurvePipe() を使用して作成されます。どちらのメソッドでも、特定のパーツ ファミリ(ファミリのオブジェクト ID を使用)と特定のパーツ サイズ フィルタ オブジェクトに加え、パイプのジオメトリを指定する必要があります。

次の例では、パーツ リストで最初に発見したパイプ ファミリとパイプ サイズ フィルタを使用して、2 つのハードコードされたポイント間に直線パイプを作成します。

[CommandMethod("AddPipe")]
public void AddPipe()
{
    CivilDocument doc = CivilApplication.ActiveDocument;
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    using (Transaction ts = Application.DocumentManager.MdiActiveDocument.
        Database.TransactionManager.StartTransaction())
    {
        ObjectIdCollection oIdCollection = doc.GetPipeNetworkIds();
        // Get the first network in the document
        ObjectId objId = oIdCollection[0];
        Network oNetwork = ts.GetObject(objId, OpenMode.ForWrite) as Network;
        ed.WriteMessage("Pipe Network: {0}\n", oNetwork.Name);
        // Go through the list of part types and select the first pipe found
        ObjectId pid = oNetwork.PartsListId;
        PartsList pl = ts.GetObject(pid, OpenMode.ForWrite) as PartsList;
        ObjectId oid = pl["Concrete Pipe"];
        PartFamily pfa = ts.GetObject(oid, OpenMode.ForWrite) as PartFamily;
        ObjectId psize = pfa[0];
        LineSegment3d line = new LineSegment3d(new Point3d(30, 9, 0), new Point3d(33, 7, 0));
        ObjectIdCollection col = oNetwork.GetPipeIds();
        ObjectId oidNewPipe = ObjectId.Null;
        oNetwork.AddLinePipe(oid, psize, line, ref oidNewPipe, false);
        Pipe oNewPipe = ts.GetObject(oidNewPipe, OpenMode.ForRead) as Pipe;                
        ed.WriteMessage("Pipe created: {0}\n", oNewPipe.DisplayName);
        ts.Commit();
    }
    
}