其他分享
首页 > 其他分享> > Civil 3d 获取横断面填挖面积

Civil 3d 获取横断面填挖面积

作者:互联网

很久以前的测试代码,

昨天QQ群中有群友询问类似的问题,

这代码放自己硬盘中也产生不了什么价值,

不如分享到这里!

有类似需求的朋友可以参考一下。

// Put your command code here
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed;
if (doc == null) return;
ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\n选择路线");
peo.SetRejectMessage("\n选择的对象必须为路线");
peo.AddAllowedClass(typeof(Alignment), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK) return;

using (Transaction tr = doc.TransactionManager.StartTransaction())
{
    Alignment alignment = per.ObjectId.GetObject(OpenMode.ForRead) as Alignment;

    try
    {
        ObjectId sampleLineGroupId = alignment.GetSampleLineGroupIds()[0];

        SampleLineGroup slg = sampleLineGroupId.GetObject(OpenMode.ForRead) as SampleLineGroup;
        var mls = slg.MaterialLists;
        foreach(QTOMaterialList ml in mls)
        {
            string name = ml.Name;
            foreach(QTOMaterial m in ml)
            {
                string name1 = m.Name;
                var t = m.QuantityType;
            }
        }
        string[] names = slg.GetQTOMappingNames();
        if (names.Length < 1)
        {
            tr.Abort();
            return;
        }
        //https://forums.autodesk.com/t5/civil-3d-customization/i-want-to-get-each-material-volume-data-not-the-total-volume/td-p/8918744?profile.language=zh-CN
        QuantityTakeoffResult qtoResult = slg.GetTotalVolumeResultDataForMaterialList(slg.GetMappingGuid(names[0]));
        QTOSectionalResult qtoSectionalResult = qtoResult.GetResultsAlongSampleLines()[1];
        QTOAreaResult qtoAreaResult = qtoSectionalResult.AreaResult;
        double cutarea = qtoAreaResult.CutArea;
        double fillarea = qtoAreaResult.FillArea;
        ed.WriteMessage("\n挖方面积为{0:0.00},填方面积为{1:0.00}", cutarea, fillarea);
    }
    catch (System.Exception ex)
    {
        ed.WriteMessage(ex.Message);
    }

    tr.Commit();
}

 

标签:return,Civil,ed,tr,peo,填挖,doc,slg,3d
来源: https://www.cnblogs.com/myzw/p/16399108.html