1. 程式人生 > >批量修改橫斷面圖高程範圍

批量修改橫斷面圖高程範圍

rap sele .data view \n 固定 data double vat

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(); } } } }

批量修改橫斷面圖高程範圍