VLISP的,这个是要在程序中打开文件并自动关闭。如果要不打开文件,则会复杂些。。。

- (vl-load-com)
- ;函数:GetFolder
- ;功能:调用Windows通用目录选取对话框,返回选中路径
- ;参数: msg-对话框提示字符串
- (defun GetFolder (msg / WinShell shFolder path catchit)
- (vl-load-com)
- (setq winshell (vlax-create-object "Shell.Application"))
- (setq
- shFolder (vlax-invoke-method WinShell 'BrowseForFolder 0 msg 1)
- )
- (setq
- catchit (vl-catch-all-apply
- '(lambda ()
- (setq shFolder (vlax-get-property shFolder 'self))
- (setq path (vlax-get-property shFolder 'path))
- )
- )
- )
- (if (vl-catch-all-error-p catchit)
- nil
- path
- )
- )
- (defun c:Tran( / Docs doc files file path i sset)
- (setq Docs (vla-get-documents (vlax-get-acad-object)))
- (setq path (GetFolder "选择文件夹"))
- (setq files (vl-directory-files path "*.dwg" 1))
- (setq sset (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
- (setq i 0)
- (repeat (length files)
- (setq file (nth i files))
- (setq doc (vla-open docs (strcat path "\" file)))
- (vla-export doc (strcat path "\" file) "DXF" sset)
- (vla-close doc)
- (vlax-release-object doc)
- (setq i (1+ i))
- )
- (vlax-release-object sset)
- (vlax-release-object docs)
- (princ)
- )
|