- UID
- 267748
- 积分
- 1257
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-5-27
- 最后登录
- 1970-1-1
|
发表于 2006-3-9 13:59:18
|
显示全部楼层
;;; 全不保存
;;; I believe Frank Whaley posted this originally.
(defun ax:CloseAll ( / item cur)
(vlax-for item (vla-get-documents (vlax-get-acad-object))
(if (= (vla-get-active item) :vlax-false)
(vla-close item :vlax-false)
(setq cur item)
)
)
;(vla-sendcommand cur "_.CLOSE ") ;; 停等 ....
;(command "._VBASTMT" "ThisDrawing.Close True")
(command "._VBASTMT" "ThisDrawing.Close False")
)
========================================================
Ref: info
From: LEndres - view profile
Date: Mon, May 1 2000 12:00 am
Email: LEndres <lend...@sesnet.com>
Groups: autodesk.autocad.customization
I tried to do something like this myself, but there are several problems with it.
First, it doesn't check to see if a command is running in the drawing. If there is a command running then the vla-close will give an error. Is there a way to test to see if a command is running and cancel it (can you use (getvar "cmdactive") inside of the vla-for loop and return the cmdactive from the correct document)?
Second, there is a problem when a new drawing has been started but not saved. I have used the vla-get-fullname property to test for this (as Frank suggested in an earlier post), but I would like to ask the user if they want to save the drawing, and if so, allow for a save as. I haven't been able to get this to work either.
Third is that the (vla-sendcommand cur "_.CLOSE") seems to be sending the close command to the command line, but not running it.
I have pasted my very pathetic code below. Perhaps someone can fix this hack job. Obviously my knowledge of visual lisp is very low! Thanks for the help.
(defun CLOSE-ALL-OPEN-FILES (/ ACADOBJ ACTDOC ITEM)
(vl-load-com)
(setq ACADOBJ (vlax-get-acad-object))
(vlax-for ITEM (vla-get-documents ACADOBJ)
(if (not (= ITEM
(vla-get-activedocument ACADOBJ)
) ;_ End =
) ;_ End not
(if (and (= (vla-get-fullname ITEM) "")
(= (vla-get-saved ITEM) :vlax-false)
) ;_ End and
(CLOSE-UNSAVED-FILE ITEM)
(progn
;Cancel command if running
(vla-close ITEM)
) ;_ End progn
) ;_ End if
) ;_ End if
) ;_ End vlax-for
(setq ACTDOC (vla-get-activedocument ACADOBJ))
(if (and (= (vla-get-fullname ACTDOC) "")
(= (vla-get-saved ACTDOC) :vlax-false)
) ;_ End and
(CLOSE-UNSAVED-FILE ACTDOC)
(progn
;Cancel command if running
(command "_.close")
(while (= (logand (getvar "CMDACTIVE") 1) 1)
(command "y")
) ;_ End while
) ;_ End progn
) ;_ End if
) ;_ End defun
(defun CLOSE-UNSAVED-FILE (ITEM / OPTION)
(vla-put-activedocument (vlax-get-acad-object) ITEM)
(initget "Yes No")
(setq OPTION (getkword "\nSave drawing? [Yes/No] <Yes>: "))
(if (or (= OPTION "") (= OPTION "Yes"))
(progn
(initdia)
;Cancel command if running
(command
"_.saveas"
(while
(= (logand (getvar "CMDACTIVE") 1)
1
) ;_ End =
(command
PAUSE
) ;_ End command
) ;_ End while
) ;_ End command
) ;_ End progn
) ;_ End if
) ;_ End defun |
|