本帖最后由 vitalgg 于 2022-4-24 14:49 编辑
那你试试这一版吧, 需要在命令输入文件夹名称。(不能有空格)
安装 @lisp 不需要系统 的安装权限,能上网就可以安装。
- (defun c:rename-layout(/ *error* dir% dwgs)
- (defun *error* (msg)
- (if (and
- (and (= 'vla-object (type doc%)))
- (null (vlax-erased-p doc%)))
- (progn
- (vla-close doc%)
- (vlax-release-object doc%)
- (vla-quit acadapp)
- ))
- (mapcar '(lambda(obj)
- (if(and (= 'vla-object (type obj))
- (null (vlax-erased-p obj)))
- (vlax-release-object obj)))
- (list dwgdocs% acadapp))
- (princ msg))
- (setq dir% (vl-string-right-trim "\\" (getstring "请输入要处理的文件夹<注意不能有空格>:")))
- (if (null (findfile dir%))(progn (alert "目录文件不存在。")(exit)))
- (setq dwgs (vl-directory-files dir% "*.dwg" 1))
- (setq acadapp (vlax-create-object "AutoCAD.Application"));; 这里要修改为你电脑上的版本
- (setq dwgdocs% (vla-get-documents acadapp))
- ;;
- (foreach file% dwgs
- (princ(strcat "处理dwg文件 " file% "... \n"))
-
- (vla-open dwgdocs% (strcat dir% "\\" file%))
- (setq doc% (vla-item dwgdocs% file%))
- ;;实操
- (if (/= (vla-get-name (vla-item (vla-get-layouts doc%) 0))
- "Model")
- (vla-put-name
- (vla-item (vla-get-layouts doc%) 0)
- (vl-filename-base file%))
- (if (/= (vla-get-name (vla-item (vla-get-layouts doc%) 1))
- "Model")
- (vla-put-name
- (vla-item (vla-get-layouts doc%) 1)
- (vl-filename-base file%))
- ))
- ;;保存
- (vla-save doc% )
- (vla-close doc%)
- )
- (vla-quit acadapp)
- (mapcar 'vlax-release-object (list doc% dwgdocs% acadapp)))
|