Author Topic: How to close all files without saving?  (Read 3930 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1420
How to close all files without saving?
« on: October 09, 2013, 03:10:01 AM »
I created a script to modify autocad, but should close autocad first
I created this part to save all files, but can not close files without saving
 
Code: [Select]
(defun c:MyOpen (/ ansr target shell result)
  (vl-load-com)
 
  (if (< 5 (setq ansr (LM:Popup "Close all files" "Do you want to SAVE ALL opened files ?" (+ 3 32))))

    (progn
      (cond
( (= 6 ansr) (command "_.saveall" ) )
( (= 7 ansr) (progn ) )
) ; cons
      (rnscrpt)
      )
    )
  )

;;------------------------=={ Open }==------------------------;;
;;                                                            ;;
;;  Uses the 'Open' method of the Shell Object to open the    ;;
;;  specified file or folder.                                 ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  target - file, folder or ShellSpecialFolderConstants enum ;;
;;------------------------------------------------------------;;
;;  Returns:  T if successful, else nil                       ;;
;;------------------------------------------------------------;;

       
(defun rnscrpt (/ target shell result) ; LEE with modify
  (if
    (and
      (or
        (eq 'INT (type (setq target "C:\\MyApp.exe")))
        (setq target (findfile target)))
      (setq shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")))
     (progn
       (setq result (vl-catch-all-apply 'vlax-invoke (list shell 'open target)))
       (vlax-release-object shell)
       (not (vl-catch-all-error-p result)))
    ))
   
;;-------------------------=={ Popup }==----------------------;;
;;                                                            ;;
;;  Displays a pop-up message box prompting the user.         ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2012 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  title - Text to be displayed in the pop-up title bar      ;;
;;  msg   - Text content of the pop-up message box            ;;
;;  flags - Integer indicating icon & button appearance       ;;
;;          Reference: http://lee-mac.com/popup.html          ;;
;;------------------------------------------------------------;;
;;  Returns:  Integer indicating the button pressed to exit   ;;
;;------------------------------------------------------------;;

(defun LM:Popup ( title msg flags / wsh res )
    (if (setq wsh (vlax-create-object "wscript.shell"))
        (progn
            (setq res (vl-catch-all-apply 'vlax-invoke-method (list wsh 'popup msg 0 title flags)))
            (vlax-release-object wsh)
            (if (null (vl-catch-all-error-p res)) res))))



« Last Edit: October 09, 2013, 10:03:16 AM by HasanCAD »

Coder

  • Swamp Rat
  • Posts: 827
Re: How to close all files without saving?
« Reply #1 on: October 09, 2013, 03:39:08 AM »
use command close without saving  :wink:

bilançikur

  • Newt
  • Posts: 82
Re: How to close all files without saving?
« Reply #2 on: October 09, 2013, 06:49:21 AM »
command: closeall <enter>?

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: How to close all files without saving?
« Reply #3 on: October 09, 2013, 07:10:36 AM »
command: closeall <enter>?

AutoCAD while ask to save or notafyer that the lisp willnot run>

Coder

  • Swamp Rat
  • Posts: 827
Re: How to close all files without saving?
« Reply #4 on: October 09, 2013, 07:50:25 AM »
Code: [Select]
( (= 6 ansr) (progn (command "_.saveall" ) ) )

I think there is no need to use progn function as shown into your routine because you have only one statement . :-D

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: How to close all files without saving?
« Reply #5 on: October 09, 2013, 08:01:53 AM »
Code: [Select]
( (= 6 ansr) (progn (command "_.saveall" ) ) )

I think there is no need to use progn function as shown into your routine because you have only one statement . :-D

There are 3 statements
YES:       to agree to save all aopened files
NO:        disagree
CANCEL: cancel the opertation in case of some files yes and some files no need to save

Coder

  • Swamp Rat
  • Posts: 827
Re: How to close all files without saving?
« Reply #6 on: October 09, 2013, 08:31:50 AM »
Code: [Select]
( (= 6 ansr) (progn (command "_.saveall" ) ) )

I think there is no need to use progn function as shown into your routine because you have only one statement . :-D

There are 3 statements
YES:       to agree to save all aopened files
NO:        disagree
CANCEL: cancel the opertation in case of some files yes and some files no need to save

I wanted to say that the progn function can obtain multiple expressions and since you have used only one expression , there is no need for that function .

Read this

http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-6B2DD269-858D-4C01-ABDB-765DD08284FE.htm,topicNumber=d30e625833
« Last Edit: October 09, 2013, 08:35:25 AM by Coder »

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: How to close all files without saving?
« Reply #7 on: October 09, 2013, 10:02:14 AM »
I wanted to say that the progn function can obtain multiple expressions and since you have used only one expression , there is no need for that function .
I got it
I was adding more than one expression, I deleted but forget to delete progn
Thanks

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: How to close all files without saving?
« Reply #8 on: October 12, 2013, 02:05:13 AM »
is there no solution?

Kyle Reese

  • Guest
Re: How to close all files without saving?
« Reply #9 on: October 12, 2013, 06:55:06 AM »
I can't believe there isn't some old lisp routine floating around that handled this "problem" years ago.  Did you search for one?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to close all files without saving?
« Reply #10 on: October 12, 2013, 09:49:51 AM »
This works with BricsCAD:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:MyCloseAll ( / actDocObject)
  2.     (if (/= doc actDocObject)
  3.       (vla-close doc :vlax-false)
  4.     )
  5.   )
  6.   (if (zerop (getvar 'dbmod))
  7.     (command "_.close")
  8.     (command "_.close" "_no")
  9.   )
  10. )

This also work with BricsCAD:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:MyCloseAll2 ( / actDocObject)
  2.     (if (/= doc actDocObject)
  3.       (vla-close doc :vlax-false)
  4.     )
  5.   )
  6.     "_.script"
  7.     (if (zerop (getvar 'dbmod))
  8.       "C:/Test/CloseNoChanges.scr"
  9.       "C:/Test/CloseDisregardChanges.scr"
  10.     )
  11.   )
  12. )

CloseNoChanges.scr:
Code: [Select]
_.close
CloseDisregardChanges.scr:
Code: [Select]
_.close
_no


roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to close all files without saving?
« Reply #11 on: October 22, 2013, 06:39:33 AM »
@ HasanCAD: have you had time to test my suggestions?

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: How to close all files without saving?
« Reply #12 on: October 22, 2013, 07:02:21 AM »
@ HasanCAD: have you had time to test my suggestions?

Sorry for beeing late I just saw the reply.
Working perfict but do not close the active file.