欢迎来到我的博客
Civil 3D开发与应用,欢迎加入QQ群:484124761
AutoCAD开发,欢迎加入QQ群:193522571

Civil 3d中“计算材质”

根据Autodesk 论坛中的帖子修改的测试代码

在其他帖子中看到自己曾经写过类型的代码,

可惜找不到了。

前提:

采样线编组采样源已经设置完毕:

如下图:

目标:

 

测试代码:

[CommandMethod("QtoTest")]
public void C_QtoTest()
{
    CivilDocument cdoc = CivilApplication.ActiveDocument;
    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
    Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

    PromptEntityOptions peo = new PromptEntityOptions("\n拾取采样线");

    peo.SetRejectMessage("\n拾取对象应为采样线");
    peo.AddAllowedClass(typeof(SampleLine), true);

    PromptEntityResult per = ed.GetEntity(peo);
    if (per.Status != PromptStatus.OK) return;

    using (Transaction ts = Autodesk.AutoCAD.ApplicationServices.Application
        .DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
    {
        
        SampleLine sl = ts.GetObject(per.ObjectId, OpenMode.ForRead) as SampleLine;

        SampleLineGroup sampleLineGrp = ts.GetObject(sl.GroupId, OpenMode.ForWrite) as SampleLineGroup;

        SectionSourceCollection sectionSources = sampleLineGrp.GetSectionSources();

        ed.WriteMessage("Number of section sources: {0}\n", sectionSources.Count);

        ObjectIdCollection surfaceId = new ObjectIdCollection();
        ObjectId corridorId = ObjectId.Null;
        foreach (SectionSource sectionSource in sectionSources)
        {
            if ((sectionSource.SourceType == SectionSourceType.TinSurface
                || sectionSource.SourceType == SectionSourceType.CorridorSurface)
                && sectionSource.IsSampled == true)
            {
                //sectionSource.IsSampled = true;
                surfaceId.Add(sectionSource.SourceId);
            }
            else if (sectionSource.SourceType == SectionSourceType.Corridor)
            {
                corridorId = sectionSource.SourceId;
            }
        }

        QTOMaterialList qtoMaterialList = sampleLineGrp.MaterialLists.Add("填挖方");
        QTOMaterial qtoMaterial1 = qtoMaterialList.Add("填方");
        qtoMaterial1.QuantityType = MaterialQuantityType.Fill;

        QTOMaterialItem qtomaterialitem1 = qtoMaterial1.Add(surfaceId[0]);
        QTOMaterialItem qtomaterialitem2 = qtoMaterial1.Add(surfaceId[1]);
        qtomaterialitem1.Condition = MaterialConditionType.Above;
        qtomaterialitem2.Condition = MaterialConditionType.Below;

        QTOMaterial qtoMaterial2 = qtoMaterialList.Add("挖方");
        qtoMaterial2.QuantityType = MaterialQuantityType.Cut;
        qtomaterialitem1 = qtoMaterial2.Add(surfaceId[0]);
        qtomaterialitem2 = qtoMaterial2.Add(surfaceId[1]);
        qtomaterialitem1.Condition = MaterialConditionType.Below;
        qtomaterialitem2.Condition = MaterialConditionType.Above;
        //QTOMaterialGapCollection QTOMGC = qtoMaterial2.MaterialGaps;

        QTOMaterial qtoMaterial3 = qtoMaterialList.Add("基础表层");
        qtoMaterial3.QuantityType = MaterialQuantityType.Structure;
        qtomaterialitem1 = qtoMaterial3.Add(corridorId, "Base1");

        ts.Commit();
    }
}

 

posted @ 2022-05-22 09:39  david96007  阅读(351)  评论(0编辑  收藏  举报