谁能帮我写一个在cad中常数加指定范围内数字的插件?

我需要在cad中批量选中数字,然后这个数字加上一个指定范围内的随机一个整数。

该回答引用ChatGPT
请参考下面的解决方案,如果有帮助,还请点击 “采纳” 感谢支持!

以下是一个使用 Visual LISP 的示例代码:

(defun c:RandomizeNumbers ( / ent ss i)
  (setq ss (ssget "X" '((0 . "TEXT")))) ; 选择所有的数字
  (if ss
      (progn
        (setq i 0)
        (repeat (sslength ss)
          (setq ent (ssname ss i))
          (setq i (1+ i))
          (command "text" ent
                   (strcat "\\P" (itoa (random 100)))
                   "\\S0.5;\\Q"
                   (strcat "\\H" (itoa (+ (atoi (cdr (assoc 1 (entget ent)))) (random 100))))))
        (command "zoom" "e"))
    (princ "No text entities selected.")))


在上面的代码中,我们使用了 "ssget" 函数来选择所有数字,然后使用 "repeat" 循环遍历选择的实体。在循环内部,我们使用了 "entget" 函数和 "assoc" 函数来获取实体的数字值,然后使用 "random" 函数生成一个随机数,最后使用 "command" 函数更新数字。