偶尔郁闷 发表于 2025-5-22 08:41:26

合并图纸lsp,不能多选,麻烦大佬们帮忙看看


(defun c:CD (/ *error* filelst cols colgap rowgap i x y pmax pmin dx dy cdy rows)
(vl-load-com)

(defun *error* (msg)
    (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
      (princ (strcat "\n错误: " msg))
    )
    (setvar "CMDECHO" 1)
    (setvar "OSMODE" 0)
    (princ)
)

(defun GetSingleFile (/ fname)
    (setvar "FILEDIA" 1)
    (setq fname (getfiled "选择要合并的图纸" "" "dwg;dxf" 1)) ; 0表示单选模式
    (if fname (list fname))
)

(setvar "CMDECHO" 0)
(command "._UNDO" "_BEGIN")

(if (setq filelst (GetSingleFile))
    (progn
      (initget 7)
      (setq cols (getint "\n请输入列数: "))
      
      (initget 6)
      (setq colgap (getdist "\n列间距<10000>: "))
      (if (not colgap) (setq colgap 10000))
      
      (initget 6)
      (setq rowgap (getdist "\n行间距<10000>: "))
      (if (not rowgap) (setq rowgap 10000))
      
      (setq i 0 x 0 y 0 cdy 0
            rows (fix (1+ (/ (length filelst) cols)))
      )
      
      (foreach file filelst
      (if (and (< i (* cols rows)) (findfile file))
          (progn
            (princ (strcat "\n正在插入: " (vl-filename-base file)))
            (command "_.INSERT" file (list x y) "" "" "")
            
            (if (entlast)
            (progn
                (vla-getboundingbox (vlax-ename->vla-object (entlast)) 'mi 'ma)
                (setq pmax (vlax-safearray->list ma)
                      pmin (vlax-safearray->list mi)
                      dx (- (car pmax) (car pmin))
                      dy (- (cadr pmax) (cadr pmin))
                )
                (if (> dy cdy) (setq cdy dy))
               
                (setq i (1+ i))
                (if (= (rem i cols) 0)
                  (setq x 0 y (- y cdy rowgap) cdy 0)
                  (setq x (+ x dx colgap))
                )
            )
            )
          )
      )
      )
      (princ (strcat "\n成功插入 " (itoa i) " 个文件"))
    )
    (princ "\n取消文件选择")
)

(command "._UNDO" "_END")
(princ)
)
ai生成得,有大佬帮忙看下不 哪里的问题 现在选择文件只能单选无法多选。谢谢

liuhe 发表于 2025-5-22 09:00:40

lisp原生不支持多选

wwwswallow 发表于 2025-5-22 09:21:06

可以用opendcl的选择框,大海哥等大神都分享过多选对话框,可以自行搜索。

dcl1214 发表于 2025-5-22 09:50:08

帮你找ai的错误?

Andyhon 发表于 2025-5-22 17:22:22

借力Doslib--->dos_getfilem

Example
Command: (dos_getfilem "Select a file" "C:\\Program Files\\Autocad 2010\\" "Drawing files (*.dwg)|*.dwg|All files (*.*)|*.*||")

("C:\\Program Files\\AutoCAD 2010\\Sample\\" "A-01.dwg" "A-02.dwg" "A-03.dwg" "A-04.dwg" "A-05.dwg")

liunian0524 发表于 2025-5-23 08:58:03

不能选择一个包含DWG文件的文件夹吗

偶尔郁闷 发表于 2025-5-23 09:25:03

Andyhon 发表于 2025-5-22 17:22
借力Doslib--->dos_getfilem

Example


Doslib函数库可以选择文件了 但是还有其他问题 我再研究研究:lol 感谢提醒

偶尔郁闷 发表于 2025-5-23 09:26:12

liunian0524 发表于 2025-5-23 08:58
不能选择一个包含DWG文件的文件夹吗

选择整个文件夹内所有文件可以合并 我想要得是选择其中部分文件 还在研究 :lol
页: [1]
查看完整版本: 合并图纸lsp,不能多选,麻烦大佬们帮忙看看