Plot to PDF with script and LISP

Plot to PDF with script and LISP

Anonymous
Not applicable
4,468 Views
4 Replies
Message 1 of 5

Plot to PDF with script and LISP

Anonymous
Not applicable

So here's my challenge. I have a script that opens each drawing and does the following:

  • goes to my PDF layout "B-SIZE PDF"
  • opens the veiwport and does a zoom all
  • goes back to paperspace and does a zoom all
  • saves and closes the drawing.

Once it has done this to all 15 drawings, then it runs the .dsd which plots all the PDF's to a specific folder and overrides the current PDF. 

 

This takes a long time, fails if someone has one of the drawings open, and is not really efficient.  My original thought was to create a LISP to open each drawing in readonly if it is already open. Then go to the PDF layout preform the zoom all's and plot the PDF to the specific folder. I dont need to save these drawings just plot to pdf to a specific folder.

 

What I have learned is that once I open the drawing using vla-open I cant switch to the PDF layout in the drawing i just opened. it will only switch to the pdf layout in the drawing that i started the LISP in.  

 

So with this i was thinking that i could use a script and two LISP's. The script would call the open dwg LISP then it could call the PDF plot LISP that would preform the zoom all's and plot the PDF to a specific folder. I dont have much experience with LISP or scripts so i have been struggling to do this. I have spent the last few days searching forms and trying different things but I'm coming up short. Any help would be appreciated. I have attached an example drawing and below is the codes that i have so far. 

 

Open drawing LISP

; File name: Open dwg
; Created by: Ryan Fahrenkrug
; Date: 3/17/20
; Description: Opens a .dwg that is specified in the script

(defun c:dwgOpen ( Arg1 / acad ActDoc layouts)
  (vl-load-com)
  (vla-activate
    (vla-open
      (vla-get-documents
	(vlax-get-acad-object)
	)
      Arg1
      :vlax-false
     )
   )
(princ)
)

 

PDF Plot LISP

; File name: PDF Plot
; Created by: Ryan Fahrenkrug
; Date: 3/18/20
; Description: Plots the B-Size PDF layout

(defun c:PDFplot (/ doc currentPlot plotFileName)
  (vl-load-com)
  (setq doc (vla-get-activeDocument (vlax-get-acad-object)))
  (vla-put-configName (vla-get-activeLayout doc) "DWG To PDF.pc3")
  (setq currentPlot (vla-get-Plot doc)
	plotFileName "PDF Test")
  (vla-plotToFile currentPlot plotFileName)
(princ)
)

 

I havent made a script file yet since i havent gotten the pdf plot lisp to do what i want. 

0 Likes
4,469 Views
4 Replies
Replies (4)
Message 2 of 5

maratovich
Advisor
Advisor

Your action is
opens the veiwport and does a zoom all
it is a lot of time.

Could it be easier and faster to directly print from a Model?

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 3 of 5

Anonymous
Not applicable

So I open the veiwport and perform a zoom all because people dont always save the drawing with the whole drawing in the veiwport. They might have zoomed in to make a quick PDF of a section of the drawing then saved and closed the drawing. So if i plot these then i dont get the entire part and i have to open the drawing and fix it anyway.

 

As for ploting from model, if i do that then i dont have my titleblock. 

0 Likes
Message 4 of 5

Anonymous
Not applicable

So I have the pdf plot lisp working but i still need to fine tune the dwgopen lisp to get it to work properly and tie it all together in a script. I've tried what i have with a simple script but the dwgopen lisp is not doing what i need it to.

 

PDF Plot LISP

; File name: PDF Plot
; Created by: Ryan Fahrenkrug
; Date: 3/18/20
; Description: Plots the B-Size PDF layout

(defun c:PDFplot (/ doc layouts PlotToFilePath PlotFileName)
  (vl-load-com)
  ;Switch to B-SIZE PDF Layout
  (setq doc (vla-get-activeDocument (vlax-get-acad-object))
	layouts (vla-get-layouts doc))
  (vla-put-ActiveLayout doc (vla-item layouts "B-SIZE PDF"))

  ;Preforms a zoom all on the model space
    (vla-put-mspace doc :vlax-true)
    (vla-get-ActivePViewport doc)
    (vla-zoomall (vlax-get-acad-object))
    (vla-put-mspace doc :vlax-false)

  ;Plots B-SIZE PDF Layout and places the PDF in the PDF layouts folder
  (setq PlotToFilePath "<folder path>"
	PlotFileName (strcat PlotToFilePath (vl-filename-base (getvar 'dwgname))))
  (command "-plot" "n" "B-SIZE PDF" "" "" PlotFileName "n" "y")
(princ)
)
0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

1 I would use the script to open a dwg. Read only mode may be a problem.

2 In script load / run a lisp that does the plot part.

3 don't need zoom all just Pspace, I use Plot window so it has area to be plotted. 

4 have a plot range of layouts so script could have this as an extra 1,99 the 99 is used as a max value so would plot say 5 layouts.

 

0 Likes