Results 1 to 2 of 2

Thread: open a new drawing and close the old one in the same lisp routine

  1. #1
    Member
    Join Date
    2015-01
    Posts
    43
    Login to Give a bone
    0

    Default open a new drawing and close the old one in the same lisp routine

    I would like to open a drawing in AutoCAD 2018 (MDI), then use a lisp routine that includes the following code:

    - (setq Filename "C:\\ProjDir\\NewDwg.dwg")

    - (command "-EXPORTTOAUTOCAD" "F" "2000" "" Filename) to save the original to a new drawing.

    - (vla-activate (vla-open (vla-item OpenDrawingsCollection (strcase Filename)))) to open the new drawing and make it the active drawing (kudos to Tharwat for helping me with this part).

    This all works fine but I want to add the ability to close the original drawing to this routine and I can't figure out how to do it. What I think is happening is that if I close the original drawing before opening the new drawing, the lisp routine closes as well since I'm closing the namespace. But if I open the new drawing first then I think acad.lsp, acaddoc.lsp s::startup, etc. is killing my lisp routine when the new drawing opens.

    Does anyone know if I'm right about this and what I want to do is impossible (at least in LISP) or is there someway to have this functionality?

    Thanks for any help with this

  2. #2
    Member
    Join Date
    2009-09
    Posts
    10
    Login to Give a bone
    0

    Default Re: open a new drawing and close the old one in the same lisp routine

    Quote Originally Posted by deheylen690271 View Post
    I would like to open a drawing in AutoCAD 2018 (MDI), then use a lisp routine that includes the following code:

    - (setq Filename "C:\\ProjDir\\NewDwg.dwg")

    - (command "-EXPORTTOAUTOCAD" "F" "2000" "" Filename) to save the original to a new drawing.

    - (vla-activate (vla-open (vla-item OpenDrawingsCollection (strcase Filename)))) to open the new drawing and make it the active drawing (kudos to Tharwat for helping me with this part).

    This all works fine but I want to add the ability to close the original drawing to this routine and I can't figure out how to do it. What I think is happening is that if I close the original drawing before opening the new drawing, the lisp routine closes as well since I'm closing the namespace. But if I open the new drawing first then I think acad.lsp, acaddoc.lsp s::startup, etc. is killing my lisp routine when the new drawing opens.

    Does anyone know if I'm right about this and what I want to do is impossible (at least in LISP) or is there someway to have this functionality?

    Thanks for any help with this
    Try ...
    ;;; the active doc you like to close ...
    (setq doc_old_o(vla-get-activedocument(vlax-get-acad-object)))

    ;;; destination filename ...
    (setq Filename "C:/ProjDir/NewDwg.dwg")

    ;;; indicating Filename do not exist ...
    (command "-EXPORTTOAUTOCAD" "F" "2000" "" Filename)

    ;;; open not activated instance ...
    (setq doc_new_o(vla-open(vla-item OpenDrawingsCollection Filename)))

    ;;; let all opened DWG's know about the old instance you want to close ...
    (vl-propagate doc_old_o)

    ;;; activate filename instance ...
    (vla-activate doc_new_o)

    ;;; in Filename instance close the doc_old_o ...
    (vla-close doc_old_o :vlax-false)

    ... have a nice day ... rob

Similar Threads

  1. Replies: 7
    Last Post: 2018-04-13, 03:57 AM
  2. open Drawing using AutoLISP and run lisp routine
    By avinash patil in forum AutoLISP
    Replies: 0
    Last Post: 2016-03-07, 10:51 AM
  3. Close drawing in LISP with dialog box
    By Phil Gravel in forum AutoLISP
    Replies: 0
    Last Post: 2012-12-17, 03:58 PM
  4. 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
  5. VBA Open and Close Drawing
    By CADdancer in forum VBA/COM Interop
    Replies: 4
    Last Post: 2006-08-09, 08:55 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
  •