清水白粥 发表于 2025-3-4 00:12:20

快速阵列,减少参数输入

本帖最后由 清水白粥 于 2025-3-4 08:07 编辑

简单的阵列功能,减少复杂的参数输入



功能:阵列功能
快捷键:ar2

优势:阵列功能可以自由修改 数量和间距

yegucheng0129 发表于 2025-3-4 14:40:38

感谢大佬分享

183017064 发表于 2025-3-4 10:48:13

优化一下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)
)

清水白粥 发表于 2025-3-4 16:07:44

183017064 发表于 2025-3-4 10:48
优化一下DS

有缺陷,用不了

chslwj521 发表于 2025-3-7 09:18:17

清水白粥 发表于 2025-3-4 16:07
有缺陷,用不了

_.ARRAYRECT
此命令只有在高版才有,测2020可行。2008不可行

清水白粥 发表于 2025-3-7 10:16:08

chslwj521 发表于 2025-3-7 09:18
_.ARRAYRECT
此命令只有在高版才有,测2020可行。2008不可行

是高版本才可以的

season_88 发表于 2025-3-19 08:50:21

谢谢大师分享
页: [1]
查看完整版本: 快速阵列,减少参数输入