Author Topic: Close current dwg and open new one?  (Read 4812 times)

0 Members and 1 Guest are viewing this topic.

CHulse

  • Swamp Rat
  • Posts: 504
Close current dwg and open new one?
« on: December 10, 2015, 07:54:16 AM »
Can anyone tell me if it is possible in lisp to close the current dwg (without save) and open a file just created (using vla-saveas)?

I'm working on a tool to make archive copies of dwgs and want to have the file close the original without saving it and switch focus to the newly created archive feel for further processing. I have no idea if this is even possible with lisp.
Appreciate any help.

Thanks
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Close current dwg and open new one?
« Reply #1 on: December 10, 2015, 09:09:43 AM »
What kind of processing would continue? Combining lisp with a script is a potential option.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Close current dwg and open new one?
« Reply #2 on: December 10, 2015, 09:10:14 AM »
Since AutoLISP runs within the document namespace, when the current drawing is closed, evaluation of the AutoLISP program will cease.

As an alternative, you could try opening the other drawing file first, and have a set of expressions defined temporarily in the acaddoc.lsp to close the previously active drawing - you might find this function useful in this regard.

Lee

hmspe

  • Bull Frog
  • Posts: 362
Re: Close current dwg and open new one?
« Reply #3 on: December 10, 2015, 09:11:58 AM »
This is not exactly what you asked for but might be something you could modify.  I wrote this for use with Bricscad, which does not have an SDI mode that matches the SDI mode in Autocad.  It redefines the OPEN command to close any open drawings (with the option to save) then calls the file dialog to allow opening a new file.
Code: [Select]
(command "undefine" "open")

(defun c:open ( / item name new_file)
  (vlax-for item (vla-get-documents (vlax-get-acad-object))                              ; for all open drawings..  .
    (if (or (= (getvar "dbmod") 0)                                                       ; has drawing been modified?                             
            (= (vla-get-saved item) :vlax-true)                                          ; has drawing been saved?
        )   
      (vla-close item :vlax-false)                                                       ; automatic close if not modified
      (progn                                                                             ; drawings has been modified...
        (setq name (vla-get-fullname item))                                              ; get the drawing's name
        (if (= name "")                                                                  ; if drawing has not been named...     
          (setq name "Drawing1.dwg")                                                     ; name it
        )
        (vla-activate item)                                                              ; make drawing current
        (setq val (acet-ui-message                                                       ; show save box
                    (strcat "Save changes to " name " ?")
                      "Bricscad"
                        35
                  )
        )
        (cond ((= val 2)
                (exit)
              ) 
              ((= val 6)       
                (vla-close item :vlax-true)                                              ; save and close
              )   
              (t
                (vla-close item :vlax-false)                                             ; close, no save
              )   
        )
      )
    )
  ) 
  (setq new_file (getfiled "Open Drawing" "" "dwg" 16))                                  ; call file open dialog
  (if (vl-file-rename new_file new_file)
    (vla-activate                                                                        ; open and activate the new drawing
      (vla-open (vla-get-documents (vlax-get-acad-object)) new_file)
    )
    (progn
      (setq val (acet-ui-message                                                         ; show save box
                  (strcat "File " new_file " is already open. Open as Read Only?")
                    "Bricscad"
                      35
                )
      )
      (if (= val 6)       
        (vla-activate                                                                    ; open and activate the new drawing
          (vla-open (vla-get-documents (vlax-get-acad-object)) new_file :vlax-true)
        )
      ) 
    )     
  ) 
  (princ)
)
[/font] 
"Science is the belief in the ignorance of experts." - Richard Feynman

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Close current dwg and open new one?
« Reply #4 on: December 10, 2015, 09:40:10 AM »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CHulse

  • Swamp Rat
  • Posts: 504
Re: Close current dwg and open new one?
« Reply #5 on: December 11, 2015, 11:43:53 AM »
What kind of processing would continue? Combining lisp with a script is a potential option.

Thanks for all the input.

I should have said - the "further processing" would be a combination of manual edits and a second, separate lisp. I had not intended to have the same lisp do further edits.
I just want to prevent the original file from being saved.
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

bfred805

  • Guest
Re: Close current dwg and open new one?
« Reply #6 on: January 04, 2016, 02:01:53 AM »
Can anyone tell me if it is possible in lisp to close the current dwg (without save) and open a file just created (using vla-saveas)?

I'm working on a tool to make archive copies of dwgs and want to have the file close the original without saving it and switch focus to the newly created archive feel for further processing. I have no idea if this is even possible with lisp.
Appreciate any help.

Thanks
I am also interested in this. I am currently working on a routing the fires -EXPORTTOACAD after cleaning a file thoroughly. I would also like to better understand how the original can close, going unmodified and the newly created file can be opened for editing. I will try out Lee's recommendation as well as Kerry's code from the other forum and let you know if I run into any issues with either that I can not resolve.