Civil 3d 几何空间点重新编号
Civil 3d软件内部功能够对几何空间点重新编号,
但是......
对于下面这种多个断续编号的情况,
想让编号连续,
操作起来那是相当的繁琐......
于是就想到写几行代码,
快速将编号“连续”起来,
于是有了下面的几行代码!
////// 2022年6月6日 Author:Myzw /// 几何空间点重新编号, /// 消除中间不连续编号 /// [CommandMethod("ReNumberTest")] public void C_CogoPtTest() { CivilDocument cdoc = CivilApplication.ActiveDocument; List<uint> nums = new List<uint>(); using (Transaction tr = doc.TransactionManager.StartTransaction()) { foreach (ObjectId id in cdoc.CogoPoints) { var pt = id.GetObject(OpenMode.ForRead) as CogoPoint; nums.Add(pt.PointNumber); } tr.Commit(); } var sortedNums = (from pt in nums orderby pt select pt).ToArray(); if (sortedNums.Length > 0) { uint tmpNum = sortedNums[0]; for (uint i = 1; i < sortedNums.Count(); i++) { tmpNum += 1; if (sortedNums[i] - tmpNum > 0) { cdoc.CogoPoints.SetPointNumber( cdoc.CogoPoints.GetPointByPointNumber( sortedNums[i]), tmpNum); } } } }
运行后的结果:
上面的代码使用linq进行了排序,
不知道这个操作是不是必须的,
也没测试。
win10+civil3d 2022下运行