Closing a document after changing the active document

Discussion in 'AutoCAD' started by Stefan Schmid, Jul 23, 2003.

  1. Hi,
    I created a new document by
    " (setq newDoc (vlax-invoke-method acadDocCol 'Add (getenv
    "QnewTemplate")))"
    and I activated the new document by
    "(vlax-invoke-method newDoc 'Activate)".
    That part works fine.
    What's not possible is to close the old document. I get the error message
    "This document is active".
    What I want to do is: Open a new document and close the old one.

    Any idea?


    Stefan Schmid
     
    Stefan Schmid, Jul 23, 2003
    #1
  2. Stefan Schmid

    Rudy Tovar Guest

    Do the opposite OPEN the NEW one and then CLOSE the OLD one.
     
    Rudy Tovar, Jul 23, 2003
    #2
  3. Stefan Schmid

    Rudy Tovar Guest

    then revert back to the old doc, it should pop open the new.
     
    Rudy Tovar, Jul 24, 2003
    #3
  4. Stefan Schmid

    Doug Broad Guest

    Stefan,
    Generally, if you want to move from one document to another automatically
    in a batch process, it is better to set SDI to 1. Then, whenever a document
    is opened, the current document is closed. (Of course, you need to run a
    save statement before that point.)

    With Lisp alone, in MDI, the task is impossible since the program is running
    in the existing documents name space, it can't close itself since the document
    is "busy". If the last statement in the program is a vba statement, then the
    task is possible. The following is a crude example:

    (defun closeopen (nextdoc / thisdoc)
    (setq thisdoc (vla-get-activedocument (vlax-get-acad-object)))
    ;;should check here whether nextdoc is already open
    (vla-open (vla-get-documents (vlax-get-acad-object))
    nextdoc)
    ;;cancel current command - will be busy otherwise
    (vla-sendcommand thisdoc "^c^c")
    ;;must use vba to close this document. This must be last
    ;;statement in program. Note: the following discards changes!
    (command "vbastmt" "activedocument.close false"))


    It is also possible with a vba macro launched with lisp or a menu macro
    from the current document.

    Command: (command "vbastmt" "closeopen (\"drawingname\")")

    --------------vba module1
    Public Function closeopen(op As String)
    Dim newdoc, olddoc As AcadDocument
    Set olddoc = ActiveDocument
    olddoc.SendCommand "^c^c"
    Set newdoc = Documents.Open(op)
    newdoc.Activate
    olddoc.Close False, olddoc.Name
    End Function

    With the lisp method shown above, the program ends with the
    document switch and can't continue processing the next document.
    VBA is far superior in MDI applications.

    Do a google groups search on these topics. They have been discussed
    and solved before. Use the crude examples above at your own risk.

    Regards,
    Doug
     
    Doug Broad, Jul 25, 2003
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.