Lisp Handoff when opening an Existing Drawing

I would like to incorporate into a lisp function with the ability to save the current drawing, open an existing drawing then do a saveas to essentially rename the drawing.  However as soon as the existing drawing is opened the Lisp ceases to function.  I can understand why since all lisp variables etc. are lost once the original drawing is closed. 

My question is this - is there a way to hand-off that information to the new drawing so the lisp continues to function ? 
Alternatively can I place 2-lisp functions in sequence in a menu selection so that the second one will automatically commence where the first one left off once the second drawing is opened ?

Any suggestions here would be great.

Thanks,

Bruce

Comments

  • One of the unique features of Bricscad's Lisp-engine is that the execution of Lisp code is not restricted to a single drawing. So what you are trying to do is possible provided that you do not close the "calling" drawing until the Lisp code finishes. See the example below.

    [code](defun c:Test1 ()
      (command "_.qsave") ; Saves the dwg in which the lisp was started.
      (command "_.open" "B002.dwg")
      (command "_.saveas" "2010" (strcat (getvar 'dwgprefix) "B002_newName.dwg"))
      (if (> (getvar 'cmdactive) 0)
        (command "_yes") ; Possible overwrite question.
      )
      (command "_.close")
      (command "_.close") ; Closes the dwg in which the lisp was started.
      (princ)
    )[/code]

    Alternative 1 (similar to your suggestions):
    You can use the (vl-bb-set) and (vl-bb-ref) functions to set blackboard variables and have on_doc_load.lsp respond to these variables (if present).

    Alternative 2:
    Create an on-the-fly script.
  • Roy,

    Is there a method in LISP to close the opened but in-active drawing without closing the now active drawing created from your sample code?

    All other information is very good and easily incorporated into my lisp function.

    Thank you for your assistance.

    Bruce
  • To my surprise even that is possible:

    [code](defun c:Test2 ( / callingDoc)
      (command "_.qsave")                                               ; Saves the calling dwg.
      (setq callingDoc (vla-get-activedocument (vlax-get-acad-object))) ; Calling dwg as object.
      (command "_.open" "B002.dwg")
      (command "_.saveas" "2010" (strcat (getvar 'dwgprefix) "B002_newName.dwg"))
      (if (> (getvar 'cmdactive) 0)
        (command "_yes") ; Possible overwrite question.
      )
      (vla-close callingDoc :vlax-false) ; Closes the calling dwg.
      (princ)
    )[/code]
This discussion has been closed.