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

Civil 3d 创建装配并添加、镜像部件

英文论坛中有人提的问题

问题我也看不懂,

就截图回复了一下,

后来他进一步描述了问题,

我大致清楚了,

虽然我之前使用代码创建装配并添加过部件,

但之前的操作仅添加一个部件,

如何添加更多的部件并镜像部件,

确实没有尝试过,

于是试着写了以下测试代码,

分享给大家。

public void C_AssTest()
{

    Document doc = Application.DocumentManager.MdiActiveDocument;

    var assId = CivilApplication.ActiveDocument.AssemblyCollection.Add("Test", AssemblyType.UndividedCrownedRoad, Point3d.Origin);
    var subAssId1 = CivilApplication.ActiveDocument.SubassemblyCollection.ImportStockSubassembly("BaseLane", "Subassembly.BasicLane", Point3d.Origin);
    var subAssId2 = CivilApplication.ActiveDocument.SubassemblyCollection.ImportStockSubassembly("ShapeTrapezoidal", "Subassembly.ShapeTrapezoidal", Point3d.Origin);

    using (Transaction tr = doc.TransactionManager.StartTransaction())
    {
        var ass = assId.GetObject(OpenMode.ForWrite) as Assembly;
        var assGroup1 = ass.AddSubassembly(subAssId1);
        assGroup1.Name = "Right";

        var assgroup2 = ass.MirrorSubassembly(subAssId1);
        assgroup2.Name = "Left";

        var subAss1 = subAssId1.GetObject(OpenMode.ForRead) as Subassembly;
        var subAss2 = assgroup2.GetSubassemblyIds()[0].GetObject(OpenMode.ForRead) as Subassembly;

        // Find Right Top Point
        var pt1 = (from x in subAss1.Points
                   orderby x.Offset descending, x.Elevation descending
                   select x).First();
        // add Second Subassembly to Right Group
        if (pt1 != null)
        {
            ass.AddSubassembly(subAssId2, pt1);
        }
        var pt2 = (from x in subAss2.Points
                   orderby x.Offset descending, x.Elevation descending
                   select x).First();
        if (pt2 != null)
        {
            ass.MirrorSubassembly(subAssId2, pt2);
        }
        tr.Commit();
    }
}

 

运行结果如下:

 

posted @ 2023-10-27 09:15  david96007  阅读(192)  评论(10编辑  收藏  举报