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

Civil 3d 几何空间点重新编号

Civil 3d软件内部功能够对几何空间点重新编号,

但是......

 

对于下面这种多个断续编号的情况,

想让编号连续,

操作起来那是相当的繁琐......

 

 于是就想到写几行代码,

快速将编号“连续”起来,

于是有了下面的几行代码!

/// <summary>
/// 2022年6月6日 Author:Myzw
/// 几何空间点重新编号,
/// 消除中间不连续编号
/// </summary>
[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下运行

 LISP版的代码如下:

(defun GetAeccDocument ()
  (setq C3D (strcat "HKEY_LOCAL_MACHINE\\"
            (if vlax-user-product-key
              (vlax-user-product-key)
              (vlax-product-key)
            )
        )
    C3D (vl-registry-read C3D "Release")
    C3D (substr
          C3D
          1
          (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1))
        )
    C3D (vla-getinterfaceobject
          (vlax-get-acad-object)
          (strcat "AeccXUiLand.AeccApplication." C3D)
        )
  )
  (vlax-get-property C3D 'ActiveDocument)
)
(defun c:ptRn ()

  (setq aeccdoc (GetAeccDocument))

  (setq cogopts (vlax-get-property aeccdoc 'Points))
  (setq n (vlax-get-property cogopts 'count))

  (if (> n 1)
    (progn
      (setq i 0)
      (setq nums '())
      (while (< i n)
    (setq pt (vla-item cogopts i))
    (setq nums (append nums (list (vlax-get-property pt 'Number))))
    (setq i (+ 1 i))
      )
      (setq nums (vl-sort nums '<))
      (setq i 1)
      (setq tmpNum (car nums))
      (while (< i n)
    (setq tmpNum (+ 1 tmpNum))
    (if (> (- (nth i nums) tmpNum) 0)
      (progn
        (setq pt (vlax-invoke cogopts 'find (nth i nums)))
        (vlax-put-property pt 'Number tmpNum)
      )
    )
    (setq i (+ 1 i))

      )
    )
  )
  (princ)
)
(princ "\n输入命令ptrn连续点编号!")

 

posted @ 2022-06-06 15:40  david96007  阅读(201)  评论(0编辑  收藏  举报