+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Junior Member
    Using
    AutoCAD 2013
    Join Date
    Nov 2015
    Posts
    11

    Default Script to open read only and plot drawings by lisp

    Registered forum members do not see this ad.

    I create a script:
    Code:
    (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) "C:/TEST/PlotDrawing.dwg" :VLAX-TRUE)) (load "C:\\TEST\\PDF.lsp") (c:pdf) _close Y
    However, the command [ (load "C:\\TEST\\PDF.lsp") (c:pdf) _close ] do not run on PlotDrawing.

    PDF.lsp is just using -plot to plot pdf by setting A3 size and plotter which are different from drawing default.

    I would like to open the drawing by read only then using lisp to plot drawings. (in case of any other have opened the drawing)

  2. #2
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,879

    Default

    There was a way of testing for read only in case of dwg alerady open do a search. Change your method to a script may be better, the script can have lisp in it like your (load "pdf") etc this will run over multiple drawings open and closing in sequence.
    A man who never made mistakes never made anything

  3. #3
    Junior Member
    Using
    AutoCAD 2013
    Join Date
    Nov 2015
    Posts
    11

    Default

    Quote Originally Posted by BIGAL View Post
    There was a way of testing for read only in case of dwg alerady open do a search. Change your method to a script may be better, the script can have lisp in it like your (load "pdf") etc this will run over multiple drawings open and closing in sequence.
    I have already used Script file to run my code
    Originally, I use "open" to script file
    Code:
    open "C:\TEST\PlotDrawing.dwg" (load "C:\\TEST\\PDF.lsp") (c:pdf) _close Y
    However, when someone is open the drawing already, the script will stop and ask "Open file read only? (Y)". After manually enter "Y", the script will continue.

    The "Open file read only? (Y)" will only show when someone opened the drawing.

    I tried to change like this
    Code:
    open "C:\TEST\PlotDrawing.dwg" Y (load "C:\\TEST\\PDF.lsp") (c:pdf) _close Y
    When no one is opening the drawing, It will stop to show [Y Unknown command "Y". Press F1 for help.]

    Therefore, I change the code to the first post
    Code:
    (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) "C:/TEST/PlotDrawing.dwg" :VLAX-TRUE)) (load "C:\\TEST\\PDF.lsp") (c:pdf) _close Y
    How can I dual with this issue?

  4. #4
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,879

    Default

    Just a quick maybe check if DWL* exists for the dwg name to be opened, if so that says some one has it open and need the "Y". Only problem is if you exit using red cross or it crashes you can get DWL's left behind could check date also as a double check. I clean up dwl's all the time on our server.
    A man who never made mistakes never made anything

  5. #5
    Junior Member
    Using
    AutoCAD 2013
    Join Date
    Nov 2015
    Posts
    11

    Default

    Thank for the tips.

    I have tried again in below scripts but failure.
    Code:
    (defun _FileOpen-p ( filename / f ) (if (setq f (open filename "a")) (close f) t))
    (setq ofile "C:\TEST\PlotDrawing.dwg")
    (if (_FileOpen-p ofile)
    open "C:\TEST\PlotDrawing.dwg" Y (load "C:\\TEST\\PDF.lsp") (c:pdf) _close Y
    open "C:\TEST\PlotDrawing.dwg" (load "C:\\TEST\\PDF.lsp") (c:pdf) _close Y
    )
    Code:
    (defun _FileOpen-p ( filename / f ) (if (setq f (open filename "a")) (close f) t))
    (setq ofile "C:\TEST\PlotDrawing.dwg")
    open "C:\TEST\PlotDrawing.dwg" (if (_FileOpen-p ofile) Y) (load "C:\\TEST\\PDF.lsp") (c:pdf) _close Y
    how could I do the check while the script is running?

  6. #6
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,879

    Default

    Think about this using the vla method you check if TRUE but what about False so need the line twice read-only or not.
    A man who never made mistakes never made anything

  7. #7
    Junior Member
    Using
    AutoCAD 2013
    Join Date
    Nov 2015
    Posts
    11

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by BIGAL View Post
    Think about this using the vla method you check if TRUE but what about False so need the line twice read-only or not.
    I dont know how to using vla method to check.

    In my code, it is stop the script after open the drawings.
    Code:
    (defun _FileOpen-p ( filename / f ) (if (setq f (open filename "a")) (close f) t))
    (setq ofile "C:\TEST\PlotDrawing.dwg")
    (if (_FileOpen-p ofile) (progn (vla-activate (setq adoc (vla-open (vla-get-documents (vlax-get-acad-object)) "C:\TEST\PlotDrawing.dwg" :VLAX-TRUE))) (vla-sendcommand adoc "(load "C:\\TEST\\PDF.lsp")\r") (vla-sendcommand adoc "(c:pdf)\r")))
    The process is:
    1. In active drawing A to load .scr file.
    2. open PlotDrawing.dwg and activate it
    3. nothing happen
    4. return tab to drawing A
    5. the script continue to run (load "C:\\TEST\\PDF.lsp") and (c:pdf) on drawing A

    Can anybody provide some code for me to dual with this issue?

    Thank you all.

Similar Threads

  1. Problem with open file via lisp (script)
    By danglar in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 29th Sep 2016, 10:32 am
  2. Open DWG not in Read Only Mode Lisp
    By Argo in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 2nd Nov 2015, 07:14 am
  3. Replies: 2
    Last Post: 27th Jul 2012, 05:26 am
  4. Writing a script to open a bunch of drawings read-only...
    By Comatosis in forum AutoLISP, Visual LISP & DCL
    Replies: 17
    Last Post: 3rd Sep 2011, 08:44 am
  5. How to open thefile read-only using lisp.
    By Arin9916 in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 6th Jun 2011, 03:55 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts