Results 1 to 8 of 8

Thread: How to Close Drawings

  1. #1
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default How to Close Drawings

    Hi ALL,

    Supposed I have 5 drawings opened.
    I'm now working on a drawing, say it's active.
    How to close the other 4 inactive drawings without
    any drawing name inputs at command prompt?

    Your helps are much appreciated.

  2. #2
    Active Member
    Join Date
    2015-12
    Location
    Utah
    Posts
    69
    Login to Give a bone
    0

    Default Re: How to Close Drawings

    Try this:
    Code:
    (vlax-for doc (vla-get-documents(vlax-get-acad-object))
      (if (= doc (vla-get-activedocument(vlax-get-acad-object)))
        nil
        (progn
          (if (or
    	    (= 0 (getvar "dbmod"))
    	    (= :vlax-false (vla-get-readonly doc))
    	    )
    	(vl-catch-all-apply 'vla-close (list doc :vlax-false))
    	(vl-catch-all-apply 'vla-close (list doc :vlax-true))
    	)
          )
        )
      )
    This has had very little testing, but has worked through what testing I have given it.

  3. #3
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default Re: How to Close Drawings

    Quote Originally Posted by mweaver View Post
    Try this:
    Code:
    (vlax-for doc (vla-get-documents(vlax-get-acad-object))
      (if (= doc (vla-get-activedocument(vlax-get-acad-object)))
        nil
        (progn
          (if (or
            (= 0 (getvar "dbmod"))
            (= :vlax-false (vla-get-readonly doc))
            )
        (vl-catch-all-apply 'vla-close (list doc :vlax-false))
        (vl-catch-all-apply 'vla-close (list doc :vlax-true))
        )
          )
        )
      )
    This has had very little testing, but has worked through what testing I have given it.
    Thank you very much.
    But is there a possibility to do the same job without using VLISP?
    The problem is I only know a little about VLISP.

  4. #4
    Active Member
    Join Date
    2015-12
    Location
    Utah
    Posts
    69
    Login to Give a bone
    0

    Default Re: How to Close Drawings

    Quote Originally Posted by BoKirra View Post
    Thank you very much.
    But is there a possibility to do the same job without using VLISP?
    The problem is I only know a little about VLISP.
    You have to iterate the documents collection. To do this you will need to use vlisp or vba.

    If you tried the code I posted and couldn't get it to work, put (vl-load-com) somewhere in front of it.

    Take the plunge into vlisp - come over to the dark side - there is great power in the force

  5. #5
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default Re: How to Close Drawings

    Quote Originally Posted by mweaver View Post
    You have to iterate the documents collection. To do this you will need to use vlisp or vba.

    If you tried the code I posted and couldn't get it to work, put (vl-load-com) somewhere in front of it.
    Thanks again.
    Another question, what if I want to close one inactive drawing only?
    Of course, in this case the code will ask me to input the drawing name.
    Take the plunge into vlisp - come over to the dark side - there is great power in the force
    I'll take more candles before jumping into the dark.
    I mean I'll learn it soon.
    Last edited by BoKirra; 2009-04-01 at 01:00 AM.

  6. #6
    Active Member
    Join Date
    2015-12
    Location
    Utah
    Posts
    69
    Login to Give a bone
    0

    Default Re: How to Close Drawings

    Quote Originally Posted by BoKirra View Post
    Thanks again.
    Another question, what if I want to close one inactive drawing only?
    Of course, in this case the code will ask me to input the drawing name.

    I'll take more candles before jumping into the dark.
    I mean I'll learn it soon.
    Let's look at a couple of ways of doing this. First, I would build a subroutine that would close a drawing based on the name of the drawing:
    Code:
    (defun CloseSpecifiedDwg (FileName / docs doc OurDoc)
      (vl-load-com)
      (setq
        FileName (if (wcmatch (strcase FileName) "*.DWG") FileName (strcat FileName ".DWG"))
        docs   (vla-get-documents (vlax-get-acad-object))
    					;the collection of all of the currently open drawings
        doc	   (vla-get-activedocument (vlax-get-acad-object)) ;the active drawing
        ;;Get the document we want to close
        ;;wrap this in a vl-catch-all-apply
        ;;in case the drawing isn't open
        OurDoc (vl-catch-all-apply
    	     'vla-item
    	     (list docs 1);filename)
    	   )
      )
      (if (vl-catch-all-error-p OurDoc)
        ;;then the drawing isn't open, notify the operator
        (princ (strcat "\nCan't close " FileName " because it isn't open."))
        ;;else, close it
        (vla-close OurDoc :vlax-true)
      )
      (vlax-release-object OurDoc)
      (vlax-release-object Doc)
      (vlax-release-object Docs)
    )
    Then we could call it with a this, which will prompt for the drawing name:
    Code:
    (defun c:CloseDwg1 (/ FileName)
      (setq FileName (getstring T "\nEnter name of drawing to close: "))
      (CloseSpecifiedDwg FileName)
      (princ)
    )
    This will work, but leaves a lot of room for error - typos, spelling, etc;. With a bit more code we could present the user with a "menu" on the text screen:
    Code:
    (defun c:CloseDwg2 (/)
      (vl-load-com)
      (setq
        docs (vla-get-documents (vlax-get-acad-object))
    					;the collection of all of the currently open drawings
        doc	 (vla-get-activedocument (vlax-get-acad-object)) ;the active drawing
        indx 1
      )
      ;;Create a list of the names of all the open drawings
      (princ "\n\n   Enter the drawing number to close")
      (vlax-for dwg	docs
        (princ (strcat "\n" (itoa indx) ".\t" (vla-get-name dwg)))
        (setq indx (1+ indx))
      )
      (princ "\n")
      (textscr)
      (setq OurDwgIndex (getint))
      (if (and
    	(< (1- OurDwgIndex) (vla-get-count docs))
    	(< 0 OurDwgIndex)
          )
        (closeSpecifiedDwg (vla-get-name (vla-item docs (1- OurDwgIndex))))
      )
      (vlax-release-object Docs)
    )
    Which will switch to the text screen and show a menu similar to the following:
    Code:
       Enter the drawing number to close
    1.	Drawing1.dwg
    2.	Drawing4.dwg
    3.	Drawing5.dwg
    4.	Drawing6.dwg
    5.	Drawing7.dwg
    6.	Drawing8.dwg
    I hope this helps show that routines that use vlisp functions don't have to be too complex.

  7. #7
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default Re: How to Close Drawings

    Quote Originally Posted by mweaver View Post
    Let's look at a couple of ways of doing this. First, I would build a subroutine that would close a drawing based on the name of the drawing:
    Code:
    (defun CloseSpecifiedDwg (FileName / docs doc OurDoc)
      (vl-load-com)
      (setq
        FileName (if (wcmatch (strcase FileName) "*.DWG") FileName (strcat FileName ".DWG"))
        docs   (vla-get-documents (vlax-get-acad-object))
                        ;the collection of all of the currently open drawings
        doc       (vla-get-activedocument (vlax-get-acad-object)) ;the active drawing
        ;;Get the document we want to close
        ;;wrap this in a vl-catch-all-apply
        ;;in case the drawing isn't open
        OurDoc (vl-catch-all-apply
             'vla-item
             (list docs 1);filename)
           )
      )
      (if (vl-catch-all-error-p OurDoc)
        ;;then the drawing isn't open, notify the operator
        (princ (strcat "\nCan't close " FileName " because it isn't open."))
        ;;else, close it
        (vla-close OurDoc :vlax-true)
      )
      (vlax-release-object OurDoc)
      (vlax-release-object Doc)
      (vlax-release-object Docs)
    )
    Then we could call it with a this, which will prompt for the drawing name:
    Code:
    (defun c:CloseDwg1 (/ FileName)
      (setq FileName (getstring T "\nEnter name of drawing to close: "))
      (CloseSpecifiedDwg FileName)
      (princ)
    )
    This will work, but leaves a lot of room for error - typos, spelling, etc;. With a bit more code we could present the user with a "menu" on the text screen:
    Code:
    (defun c:CloseDwg2 (/)
      (vl-load-com)
      (setq
        docs (vla-get-documents (vlax-get-acad-object))
                        ;the collection of all of the currently open drawings
        doc     (vla-get-activedocument (vlax-get-acad-object)) ;the active drawing
        indx 1
      )
      ;;Create a list of the names of all the open drawings
      (princ "\n\n   Enter the drawing number to close")
      (vlax-for dwg    docs
        (princ (strcat "\n" (itoa indx) ".\t" (vla-get-name dwg)))
        (setq indx (1+ indx))
      )
      (princ "\n")
      (textscr)
      (setq OurDwgIndex (getint))
      (if (and
        (< (1- OurDwgIndex) (vla-get-count docs))
        (< 0 OurDwgIndex)
          )
        (closeSpecifiedDwg (vla-get-name (vla-item docs (1- OurDwgIndex))))
      )
      (vlax-release-object Docs)
    )
    Which will switch to the text screen and show a menu similar to the following:
    Code:
       Enter the drawing number to close
    1.    Drawing1.dwg
    2.    Drawing4.dwg
    3.    Drawing5.dwg
    4.    Drawing6.dwg
    5.    Drawing7.dwg
    6.    Drawing8.dwg
    I hope this helps show that routines that use vlisp functions don't have to be too complex.
    WOW!
    What a great help!
    I don't know how to say something else but "THANKS, WONDERFUL, INCREDIBLE..."

  8. #8
    Active Member
    Join Date
    2015-12
    Location
    Utah
    Posts
    69
    Login to Give a bone
    0

    Default Re: How to Close Drawings

    I'm glad to help.

    Mike

Similar Threads

  1. Open all drawings in a directory, save, close.
    By JSimons in forum AutoLISP
    Replies: 18
    Last Post: 2020-05-08, 10:08 PM
  2. Clean your drawings before you start or bofore you close
    By kmwpgca in forum CAD Management - General
    Replies: 4
    Last Post: 2012-04-24, 06:57 PM
  3. VBA routine to save and close some open drawings
    By GreyHippo in forum VBA/COM Interop
    Replies: 1
    Last Post: 2010-03-24, 11:59 AM
  4. Search text within drawings, without actually opening drawings
    By Animesh Kundu in forum AutoCAD General
    Replies: 3
    Last Post: 2008-02-29, 05:34 PM
  5. Publish does not close drawings
    By smplancic in forum AutoCAD General
    Replies: 7
    Last Post: 2007-12-13, 04:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •