can this be modified to open as read-only?

Discussion in 'AutoCAD' started by James Maeding, Mar 18, 2005.

  1. I did this to qsave, close and then open a given drawing.
    It works very nicely for both SDI 1 and 0.
    Someone asked me if I could modify it to open the drawing as read-only.
    You can see in the code, I am using the open command to do this, not:

    (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) <filename> :VLAX-TRUE))

    which is how to do it with activex commands.

    I tried the above code in a script (with a real filename) and it did not work.
    To be able to do what is needed, this code needs to work even if no drawings are open.
    That is what you have to do when switching drawings and why the script approach is necessary.
    thx

    ;FUNCTION TO OPEN DRAWING, SAVES AND CLOSES CURRENT DRAWING
    ;Can we make this open as read only?

    (DEFUN JUMP-2-FILE (FILENAME / ADOC RO-SCRIPT)
    (SETQ ADOC (vla-get-ActiveDocument (vlax-get-acad-object)))
    ;CHECK IF SDI IS 0 OR MORE
    (IF (> (GETVAR "SDI") 0)
    ;SINGLE DOC, SAVE AND REOPEN
    (PROGN
    ;SAVE IF NOT READ-ONLY
    (IF (= (vla-get-ReadOnly ADOC) :vlax-false)
    (COMMAND ".QSAVE")
    )
    ;REOPEN
    (COMMAND ".OPEN" FILENAME)
    )
    ;MULTIPLE DOC, SAVE CLOSE AND REOPEN
    (PROGN
    ;SAVE IF NOT READ-ONLY
    (IF (= (vla-get-ReadOnly ADOC) :vlax-false)
    (COMMAND ".QSAVE")
    )
    ;CLOSE DRAWING, NOW WE SWITCH TO SCRIPT SINCE OPEN COMMAND MUST FOLLOW
    (IF (SETQ RO-SCRIPT (OPEN "C:\\RO-SCRIPT.SCR" "w"))
    (PROGN
    ;(WRITE-LINE (STRCAT "CLOSE OPEN \"" (GETVAR "DWGPREFIX")(GETVAR "DWGNAME") "\"") RO-SCRIPT)
    (WRITE-LINE (STRCAT "CLOSE OPEN \"" FILENAME "\"") RO-SCRIPT)
    (CLOSE RO-SCRIPT)
    )
    )
    )
    )
    (IF RO-SCRIPT (COMMAND ".SCRIPT" "C:\\RO-SCRIPT.SCR"))
    )
    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Mar 18, 2005
    #1
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.