求助一个LISP, 完整可运行的。刷标注成小数点后一位标注。
求助一个LISP,完整可运行的。刷标注成小数点后一位标注。(defun c:tt( / e en rd rd1 sd1 ti%)
(princ "\n选择要修改的尺寸:")
(setq sd1 (ssget '((0 . "DIMENSION"))))
(setq ti% 0)
(repeat(sslength sd1)
(setq en (ssname sd1 ti%))
(setq e (entget en))
(setq rd (cdr (assoc 42 e)))
(if (equal (fix rd) (fix (+ 0.1 rd)) 0)
(setq rd1 (rtos (fix rd) 2 0))
(setq rd1 (rtos (+ (fix rd) 0.1) 2 1))
)
(entmod (subst (cons 1rd1) (assoc 1 e) e))
(setq ti% (+ 1 ti%))
)
)
不知道为什么老是报错,能麻烦看一下吗,想将框选的所有标注改成,自己想要的小数点后一位。或两位。默认是1位,希望自己可以设置改
本帖最后由 cds15980954301 于 2025-3-22 23:14 编辑
469229020@QQ.CO 发表于 2025-3-21 01:45
(defun c:tt( / e en rd rd1 sd1 ti%)
(princ "\n选择要修改的尺寸:")
(setq sd1 (ssget '((0 . "DI ...
理解错误了
;;; 功能:修改选中标注的小数位数
;;; ----------------------------- 主函数 -----------------------------
(defun c:HHMDP (/ HHSelectionSet HHDecimalPlaces HHCount HHEntity HHDimObj HHMeasurement HHFormattedText)
; 加载Visual LISP扩展函数
(vl-load-com)
; 初始化变量
(setq HHDecimalPlaces (HHGetUserPreference)) ; 从注册表读取用户设置
; 提示用户输入小数位数
(initget 6) ; 不允许空值和负数
(setq HHDecimalPlaces
(cond
((getint (strcat "\n请输入小数位数 <" (itoa HHDecimalPlaces) ">: ")))
(HHDecimalPlaces)
)
)
; 保存用户设置到注册表
(HHSetUserPreference HHDecimalPlaces)
; 选择标注对象(仅限线性和对齐标注)
(princ "\n请框选线性或对齐标注对象...")
(setq HHSelectionSet (ssget '((0 . "DIMENSION,DIMALIGNED"))))
(if (not HHSelectionSet)
(princ "\n未选择标注对象或选择无效。")
(progn
; 遍历选中的标注对象
(setq HHCount 0)
(repeat (sslength HHSelectionSet)
(setq HHEntity (ssname HHSelectionSet HHCount))
(setq HHDimObj (vlax-ename->vla-object HHEntity))
; 检查是否为有效标注对象
(if (vlax-property-available-p HHDimObj 'Measurement)
(progn
; 获取标注测量值
(setq HHMeasurement (vla-get-Measurement HHDimObj))
; 格式化测量值为指定小数位数
(setq HHFormattedText (rtos HHMeasurement 2 HHDecimalPlaces))
; 直接修改标注文字(保留原始单位)
(vla-put-TextOverride HHDimObj HHFormattedText)
(setq HHCount (1+ HHCount))
)
)
)
(princ (strcat "\n已修改 " (itoa HHCount) " 个标注的小数位数为 " (itoa HHDecimalPlaces) " 位。"))
)
)
(princ)
)
;;; ----------------------------- 功能函数 -----------------------------
;;; 从注册表读取用户设置
(defun HHGetUserPreference (/ HHRegKey HHValue)
(setq HHRegKey (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\HHModifyDimPrecision"))
(setq HHValue (vl-registry-read HHRegKey "DecimalPlaces"))
(if (null HHValue)
(progn
(vl-registry-write HHRegKey "DecimalPlaces" "1") ; 默认值
(setq HHValue 1)
)
(setq HHValue (atoi HHValue))
)
HHValue
)
;;; 保存用户设置到注册表
(defun HHSetUserPreference (HHDecimalPlaces / HHRegKey)
(setq HHRegKey (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\HHModifyDimPrecision"))
(vl-registry-write HHRegKey "DecimalPlaces" (itoa HHDecimalPlaces))
)
;;; ----------------------------- 加载提示 -----------------------------
(princ "\n命令已加载。输入HHMDP运行。")
(princ)
页:
[1]