Author Topic: Close all open drawings  (Read 7797 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Close all open drawings
« on: July 13, 2009, 11:12:40 AM »
I have this function in my next and previous drawing routine. The problem is that it is buggy and doesnot always work, thus locking up AutoCAD. Anybody have any ideas?

Code: [Select]
;;;Here is another one that will close all open documents except the current one.
;;;by Peter Jamtgaard
(defun ARCH:Close_All  (/ DOCOBJ FULL)
  (vl-load-com)
  (vlax-for
         DOCOBJ  (vla-get-documents (vlax-get-acad-object))
    (setq FULL (strcat (vla-get-path DOCOBJ) "\\" (vla-get-name DOCOBJ)))
    (if (= (vla-get-active DOCOBJ) :vlax-false)
      (if (vl-catch-all-error-p
            (vl-catch-all-apply
              '(lambda (X) (vla-close X :vlax-true FULL))
              (list DOCOBJ)))
        (princ (strcat "\nCan not close drawing "
                       FULL
                       " with active command in progress:")))))
  (princ))
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Close all open drawings
« Reply #1 on: July 13, 2009, 11:28:03 AM »
Here is mine.  Pretty much the same thing, but mine doesn't try and save them.  It hasn't locked up my Acad though.

Code: [Select]
(defun c:CloseAllButActive(/ tmpList)
   
    (vl-load-com)
    (vlax-for item (vla-get-documents (vlax-get-acad-object))
        (if (= (vla-get-active item) :vlax-false)
            (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-close (list item :vlax-false)))
                (setq tmpList (cons item tmpList))
            )
        )
    )
    (foreach item tmpList
        (prompt (strcat "\n Drawing could not be closed \"" (vla-get-name item) "\"."))
    )
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Close all open drawings
« Reply #2 on: July 13, 2009, 12:00:16 PM »
Thanks Tim, seems tobe working pecrfectly. I'm using it with your routines: "MyNext" and MyPrevious".
I use these two routines all of the time. Thanks for sharing them.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Close all open drawings
« Reply #3 on: July 13, 2009, 12:07:02 PM »
Thanks Tim, seems tobe working pecrfectly. I'm using it with your routines: "MyNext" and MyPrevious".
I use these two routines all of the time. Thanks for sharing them.

I use them all the time also.  Good to hear that are still worth using.  You're welcome Gary.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Close all open drawings
« Reply #4 on: July 23, 2009, 05:37:10 PM »
Ok you lisp guru's, is there a way to open drawings in a directory using Tim's "mynext" and "myprevious" without vba?
It would be great to have these functions for autocad 2010, since it does not support vba.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Close all open drawings
« Reply #5 on: July 23, 2009, 05:44:28 PM »
Here's two for you  :-)

Open All Drawings in a Directory:

Code: [Select]
;; Open_all by Lee Mac

(defun c:open_all (/ path dwg)
  (if (setq path (Directory-Dia "Select Directory: "))
    (progn
      (foreach dwg (mapcar
                     (function
                       (lambda (file)
                         (strcat path file)))
                     (vl-directory-files path "*.dwg" 1))
      (if (vl-catch-all-error-p
            (vl-catch-all-apply
              (function
                (lambda ( )
                  (vla-open
                    (vla-get-Documents
                      (vlax-get-acad-object)) dwg :vlax-false)))))
        (princ (strcat "\n** " dwg " Failed to Open **")))))
    (princ "\n*Cancel*"))
  (princ))

(defun Directory-Dia  (Message / sh folder folderobject result)
  ;; By Tony Tanzillo
  (vl-load-com)
  (setq sh (vla-getInterfaceObject
             (vlax-get-acad-object) "Shell.Application"))
  (setq folder (vlax-invoke-method sh 'BrowseForFolder
                 (vla-get-HWND
                   (vlax-get-Acad-Object)) Message 0))
  (vlax-release-object sh)
  (if folder
    (progn
      (setq folderobject (vlax-get-property folder 'Self)
            result (vlax-get-property FolderObject 'Path))
      (vlax-release-object folder)
      (vlax-release-object FolderObject)
      (if (/= (substr result (strlen result)) "\\")
        (setq result (strcat result "\\"))
        result))))

Open Latest Drawing in a Directory:

Code: [Select]
;; Open_last by Lee Mac

(defun c:open_last (/ path lst dwg)
  (if (setq path (Directory-Dia "Select Directory: "))
    (progn
      (foreach dwg (mapcar
                     (function
                       (lambda (file)
                         (strcat path file)))
                     (vl-directory-files path "*.dwg" 1))
        (setq lst
               (cons
                 (list dwg (remove_nth (vl-file-systime dwg) 2)) lst)))
      (if (vl-catch-all-error-p
            (vl-catch-all-apply
              (function
                (lambda ( )
                  (vla-open
                    (vla-get-Documents
                      (vlax-get-acad-object))
                    (setq dwg (dSort lst)) :vlax-false)))))
        (princ (strcat "\n** " dwg " Failed to Open **"))))
    (princ "\n*Cancel*"))
  (princ))

(defun Directory-Dia  (Message / sh folder folderobject result)
  ;; By Tony Tanzillo
  (vl-load-com)
  (setq sh (vla-getInterfaceObject
             (vlax-get-acad-object) "Shell.Application"))
  (setq folder (vlax-invoke-method sh 'BrowseForFolder
                 (vla-get-HWND
                   (vlax-get-Acad-Object)) Message 0))
  (vlax-release-object sh)
  (if folder
    (progn
      (setq folderobject (vlax-get-property folder 'Self)
            result (vlax-get-property FolderObject 'Path))
      (vlax-release-object folder)
      (vlax-release-object FolderObject)
      (if (/= (substr result (strlen result)) "\\")
        (setq result (strcat result "\\"))
        result))))

; Stig
(defun remove_nth (lst i / a)
  (setq a -1)
  (vl-remove-if
    (function
      (lambda (n) (= (setq a (1+ a)) i))) lst))

(defun dSort (lst / lst)
  (while
    (progn
      (cond ((not
               (vl-remove-if 'null
                 (mapcar 'cadr lst)))
             (setq lst nil))
            ((apply '=
               (vl-sort
                 (mapcar 'caadr lst)
                   (function
                     (lambda (a b) (< a b)))))
             (setq lst (mapcar
                         (function
                           (lambda (x)
                             (list (car x) (cdadr x)))) lst)))
            (t (setq lst (caar lst)) nil))))
  lst)

Enjoy :P
« Last Edit: June 27, 2012, 07:21:31 AM by Lee Mac »

GDF

  • Water Moccasin
  • Posts: 2081
Re: Close all open drawings
« Reply #6 on: July 23, 2009, 06:02:05 PM »
Thanks Lee

Here is the link to Tim's "Mynext" and "Myprevious" routines. These are the most used routines in our office.
It's just over my head to rework...Maybe I can nudge Tim Willey.
http://www.theswamp.org/index.php?topic=21986.0
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Close all open drawings
« Reply #7 on: July 23, 2009, 06:05:28 PM »
Are the routines I posted not suitable for your purpose?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Close all open drawings
« Reply #8 on: July 23, 2009, 06:31:09 PM »
Do the .Net ones not work anymore?  My .Net stuff works in '09, but haven't tried in '10.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Close all open drawings
« Reply #9 on: July 23, 2009, 06:31:43 PM »
Are the routines I posted not suitable for your purpose?

Lee

Thanks for your routines.

Please refer to Tim's routines which open the next or previous drawings in the current directory.
While you have a drawing open in the current directory, you can open the next drawing and so on.
Very useful for scrolling to the next drawing without having to go with the open command or without having to browse.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Close all open drawings
« Reply #10 on: July 23, 2009, 06:33:52 PM »
Do the .Net ones not work anymore?  My .Net stuff works in '09, but haven't tried in '10.

Hi Tim

May have to refresh my bad memory. I think I remember them, but have not used them.
I think they should work. That right they are the dll routine taht has to be registered.

I will give them a try.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Close all open drawings
« Reply #11 on: July 23, 2009, 06:35:57 PM »
Do the .Net ones not work anymore?  My .Net stuff works in '09, but haven't tried in '10.

Hi Tim

May have to refresh my bad memory. I think I remember them, but have not used them.
I think they should work. Can you post the link to your routines?

They are the ones in the link you posted.  The ones you should be using are the .Net ones, not the Lisp ones.  IIRC that is.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Close all open drawings
« Reply #12 on: July 23, 2009, 06:52:37 PM »
Are the routines I posted not suitable for your purpose?

Lee

Thanks for your routines.

Please refer to Tim's routines which open the next or previous drawings in the current directory.
While you have a drawing open in the current directory, you can open the next drawing and so on.
Very useful for scrolling to the next drawing without having to go with the open command or without having to browse.

I see -

They sound like some top-class functions - nice one Tim  :-)

GDF

  • Water Moccasin
  • Posts: 2081
Re: Close all open drawings
« Reply #13 on: July 23, 2009, 06:57:55 PM »
Tim, yes they work, I had to revise the reg code to the following:

Code: [Select]
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\NextPrev18\Groups]
"Support"="Support"


[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\NextPrev18]
"DESCRIPTION"="Next Previous Drawing in the Directory"
"LOADCTRLS"=dword:00000004
"LOADER"="C:\\Arch_Custom\\Support\\NextPrev18.dll"
"MANAGED"=dword:00000001

[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\NextPrev18\Commands]
"MyNext"="MyNext"
"MyPrevious"="MyPrevious"

Thanks again Tim. Works perfectly in version 2010.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Close all open drawings
« Reply #14 on: July 23, 2009, 07:00:35 PM »
Thanks Lee.  I also use them, and find them valuable.

Good to hear Gary.  Thanks for confirming.  That is the good time about .Net over ObjectArx.  Don't have to recompile as often.   :wink:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.