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

批量修改横断面图高程范围

Civil 3D横断面图编组特性中虽然有手动设置高程选项,

但其功能不符合某些特殊需求,

比如要将所有横断面的高程范围设置成固定的范围,

如果手工指定高程范围,

需要单独操作每一个横断面图,

在实际工作中显然不能满足要求。

此时就提现出二次开发的必要性了。

几十行的代码就能满足要求。

 

代码如下:

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.Civil.DatabaseServices;

namespace 翻模工具
{
    class SetSectionViewHeight
    {
        public void Do()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application
               .DocumentManager.CurrentDocument;
            Database db = doc.Database;
            PromptDoubleOptions pdo = new PromptDoubleOptions("\n横断面图最小高程为");
            pdo.AllowArbitraryInput = false;
            pdo.AllowNone = false;
            PromptDoubleResult pdr = doc.Editor.GetDouble(pdo);
            if (pdr.Status != PromptStatus.OK) return;
            double minEle = pdr.Value;
            pdo.Message = "\n横断面图整体高度";
            pdr = doc.Editor.GetDouble(pdo);
            if (pdr.Status != PromptStatus.OK) return;
            double maxEle = minEle + pdr.Value;

            TypedValue[] tv = new TypedValue[]
            {
                new TypedValue((int)DxfCode.Start,"AECC_GRAPH_SECTION_VIEW")

            };
            SelectionFilter sf = new SelectionFilter(tv);
            PromptSelectionResult psr = doc.Editor.GetSelection(sf);
            if (psr.Status != PromptStatus.OK) return;
            SelectionSet ss = psr.Value;
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in ss.GetObjectIds())
                {
                    SectionView sv = id.GetObject(OpenMode.ForWrite) as SectionView;
                    if (sv.IsElevationRangeAutomatic)
                    {
                        sv.IsElevationRangeAutomatic = false;
                    }
                    if (minEle > sv.ElevationMax)
                    {
                        sv.ElevationMax = maxEle;
                        sv.ElevationMin = minEle;
                    }
                    else
                    {
                        sv.ElevationMin = minEle;
                        sv.ElevationMax = maxEle;
                    }
                }
                tr.Commit();
            }
        }
    }
}

 

posted @ 2019-05-03 16:18  david96007  阅读(1148)  评论(1编辑  收藏  举报