- (defun BatchProcessLayouts (directory includeSubDirs / doc dbx layouts layoutname files)
- ;; 获取目录下的所有图纸文件,包括子目录
- (defun GetAllDWGFiles (Dir Subs / _GetSubFolders)
- (defun _GetSubFolders (folder)
- (apply 'append
- (mapcar
- (function
- (lambda (f)
- (cons (strcat folder "\" f) (_GetSubFolders (strcat folder "\" f)))))
- (vl-remove "." (vl-remove ".." (vl-directory-files folder nil -1)))))
- )
- (apply 'append
- (mapcar
- (function
- (lambda (filepath)
- (mapcar
- (function (lambda (filename) (strcat filepath "\" filename)))
- (vl-directory-files filepath "*.dwg" 1))))
- (cons Dir (if Subs (_GetSubFolders Dir)))))
- )
- ;; 获取所有符合条件的图纸文件
- (setq files (if directory (GetAllDWGFiles directory includeSubDirs) nil))
-
- ;; 初始化ObjectDBX对象
- (defun OpenObjectDBXDocument (filename / dbxdoc acadapp)
- (setq acadapp (vlax-get-acad-object))
- (setq dbxdoc (vla-getinterfaceobject acadapp "ObjectDBX.AxDbDocument"))
- (vla-open dbxdoc filename)
- dbxdoc
- )
-
- ;; 批量处理文件
- (if files
- (foreach dwgfile files
- ;; 打开图纸文件使用ObjectDBX
- (setq dbx (OpenObjectDBXDocument dwgfile))
- (if dbx
- (progn
- (princ (strcat "\nProcessing file: " dwgfile))
- ;; 获取该图纸的Layouts集合
- (setq layouts (vla-get-Layouts dbx))
- ;; 遍历Layouts
- (vlax-for lout layouts
- (setq layoutname (vla-get-name lout))
- ;; 匹配条件并删除符合的Layout
- (if (or (wcmatch layoutname "A4横")
- (wcmatch layoutname "A4竖")
- (wcmatch layoutname "A3横")
- (wcmatch layoutname "A3坚"))
- (progn
- (princ (strcat "\nDeleting layout: " layoutname))
- (vla-delete lout)
- )
- )
- )
- ;; 保存图纸(不需要显示)
- (vla-save dbx)
- ;; 释放ObjectDBX对象
- (vlax-release-object dbx)
- )
- )
- )
- )
- (princ "\nBatch operation completed.")
- )
- (defun c:BatchDeleteLayouts (/ directory includeSubDirs)
- ;; 提示用户选择是否使用当前目录或包含子目录
- (setq directory (getstring "\nEnter directory path (or leave blank for current drawings): "))
- (if (/= directory "")
- (setq includeSubDirs (getint "\nInclude subdirectories? (1 for Yes, 0 for No): "))
- )
- ;; 调用批量处理函数
- (BatchProcessLayouts directory (= includeSubDirs 1))
- )
运行后出现如下错误:
Include subdirectories? (1 for Yes, 0 for No): 1
;错误:Automation 错误。加载应用程序时出现问题
|