优化一下DS
 - (defun c:ar2 (/ *error* ss rows cols rowSpacing colSpacing)
- ;; 定义错误处理函数
- (defun *error* (msg)
- (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
- (princ (strcat "\n错误: " msg))
- )
- (princ)
- )
-
- ;; 检查是否选中对象
- (if (setq ss (ssget '((0 . "LINE,ARC,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE,HATCH,INSERT,DIMENSION"))))
- (progn
- ;; 获取行数(正整数)
- (setq rows 1) ; 默认值
- (while
- (progn
- (setq input (getint "\n输入行数 <1>: "))
- (cond
- ((null input) nil) ; 用户回车,使用默认值
- ((<= input 0)
- (princ "行数必须大于0。")
- t ; 继续循环
- )
- (t (setq rows input) nil) ; 有效输入,退出循环
- )
- )
- )
-
- ;; 获取列数(正整数)
- (setq cols 2) ; 默认值
- (while
- (progn
- (setq input (getint "\n输入列数 <2>: "))
- (cond
- ((null input) nil)
- ((<= input 0)
- (princ "列数必须大于0。")
- t
- )
- (t (setq cols input) nil)
- )
- )
- )
-
- ;; 获取行间距(自动处理默认值)
- (setq rowSpacing
- (cond
- ((= rows 1) 0.0) ; 单行时默认0间距
- ((getdist (strcat "\n输入行间距 <" (rtos 100.0 2) ">: ")))
- (t 100.0) ; 多行时默认100
- )
- )
-
- ;; 获取列间距(带默认值)
- (setq colSpacing
- (cond
- ((getdist "\n输入列间距 <100.0>: "))
- (t 100.0)
- )
- )
-
- ;; 执行阵列命令
- (command "_.ARRAYRECT"
- ss ; 选择集
- "" ; 结束选择
- "" ; 接受默认基点
- rows ; 行数
- cols ; 列数
- rowSpacing ; 行间距
- colSpacing ; 列间距
- )
- )
- (princ "\n未选择对象。") ; 用户取消选择提示
- )
- (princ)
- )
|