Jump to content

batch PDF print lisp


cat3appr

Recommended Posts

If in layouts this could be scripted and do hundreds, lots of other code examples like this here at cadtutor. The latest one of these plots each layout sheet but then auto combines into 1 pdf as well. You need a extra bit of software but its free.

 

script

Open dwg1 (load "plotpdfall") close N
Open dwg2 (load "plotpdfall") close N
Open dwg2 (load "plotpdfall") close N

 

; plotpdf ver 2 with filename and directory as output oct 2011
; By Alan 
(defun AH:pltpdfs ( / len)
(PROMPT ".....PRINTING DRAWING TO pdf's....")
(setvar "cmddia" 0)
(setvar "filedia" 0)
(setq plotabs nil) ; in case run before
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
 (setq plotabs (cons (vla-get-name lay) plotabs))
)
(setq dwgname (GETVAR "dwgname"))
(setq len (strlen dwgname))
(setq dwgname (substr dwgname 1 (- len 4)))
(setq plottablist (acad_strlsort plotabs))
(setq len (length plottablist))
(setq x 0)
(repeat len
 (setq name (nth x plottablist))
 (princ name)
 (setq pdfname (strcat (getvar "dwgprefix") "pdf\\" dwgname "-" name))
 ;(setq pdfname (strcat (getvar "dwgprefix") dwgname "-" name))
 (if (/= name "Model")
   (progn
   (setvar "ctab" name)
   (setvar "textfill" 1)
(setvar "fillmode" 1)
    (COMMAND "-PLOT"  "Y"  "" "dwg to Pdf"
       "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE"  "N"   "W"  "-6,-6" "807,560" "1=2"  "C"
       "y" "Designlasercolour.ctb" "Y" "n" "n" "n" pdfName "N" "y"      )
   )
 )
 (setq x (+ x 1))
(setq plotnames (cons pdfname plotnames))
) ; end repeat
(setq trgfile (strcat (getvar "dwgprefix") "pdf\\" dwgname "-D" val1 "-D" val2 ".pdf")) 
) ; defun
(setq plotnames (reverse plotnames))
(AH:pltpdfs)
(if (not combinepdf)(load "mergepdfs"))
(combinepdf gsExe plotnames trgFile )

(setvar "plottransparencyoverride" 1)
(setvar "cmddia" 1)
(setvar "filedia" 1)

(princ)

 

;MergePdfs
;Merges multiple pdf (or eps) files into one
;Requires the installatoion of Ghostscript 
; make a batch file ?
;gs -sDEVICE=pdfwrite \
;    -dNOPAUSE -dBATCH -dSAFER \
;    -sOutputFile=combined.pdf \
;    first.pdf \
;    second.pdf \
;    third.pdf [...]
;Ghostscript ([url]http://www.ghostscript.com/[/url]) can be used to combine PDFs.
; Something like this should work: by Roy_043
(defun KGA_String_Join (strLst delim)
(if strLst
(apply
'strcat
(cons
(car strLst)
(mapcar '(lambda (a) (strcat delim a)) (cdr strLst))
)
)
""
)
)
; (CombinePdf 
 (setq gsexe "C:\\Program Files\\gs\\gs9.19\\bin\\gswin64c.exe")
; (setq srcFilelst  '("D:\\Tmp\\A.pdf" "D:\\Tmp\\B.pdf"))
; (setq trgfile "C:\\Acadtemp\\Total.pdf")
; )
; Note: Existing trgFile will be overwritten.
(defun CombinePdf (gsExe srcFileLst trgFile)
(startapp 
(strcat
gsExe " "
"-sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dQUIET  "
"-sOutputFile=\"" trgFile "\" "
"\"" (KGA_String_Join srcFileLst "\" \"") "\""
)
)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...