Jump to content

PDF Automation Lisp


KraZeyMike

Recommended Posts

Hi, I have the following Lisp with a working dialogue for easily saving pdf files from a drawing without having to use Publish.
 

I was wondering is it possible to tweak this code so that I can basically do the following:
- Save the pdf as the current Acad .dwg name with a user input for suffix. ie. Drawing1 Suffix.pdf
- provide the option of doing either a single layout tab plot or combining multiple into a single pdf (the same as you would in publish).

- automatically open the pdf upon completion

 

It would be so cool to have this process automated since I'm doing pdf's all the time.

 

Here's the Lisp I'm working on:

(vl-load-com)
(defun c:PDF (/ hms:get_atts filename hnd lst lst1 name otab path ss)

  (defun hms:get_atts (enm / att obj)
    (if (or (and (eq (type enm) 'ENAME)
                 (setq obj (vlax-ename->vla-object enm))
                 (eq (vla-get-hasattributes obj) :vlax-true)
            )
            (and (eq (type enm) 'VLA-OBJECT)
                 (setq obj enm)
                 (eq (vla-get-hasattributes obj) :vlax-true)
            )
        )
      (mapcar
        '(lambda (att)
           (cons (vla-get-TagString att) (vla-get-TextString att))
         )
        (vlax-invoke obj "GetAttributes")
      )
    )
  )

  (cond ((setq path (acet-ui-pickdir "Select directory" (getvar "dwgprefix")))
         (setq otab (getvar 'CTAB))
         (foreach layt (layoutlist)
           (setvar 'CTAB layt)
           (if (setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "title_block_name") '(66 . 1) (cons 410 (getvar 'CTAB)))))
             (progn
               (setq hnd  (ssname ss 0)
                     lst  (hms:get_atts hnd)
                     lst1 '("DRAWING_NUMBER" "SHEET_NUMBER" "REVISION_NUMBER" "SHEET_SIZE")
                     name ""
               )
               (foreach n lst1
                 (if (setq a (assoc n lst))
                   (setq name (strcat name "-" (cdr a)))
                 )
               )
               (setq filename (strcat path "\\" (vl-string-left-trim "-" name) ".pdf"))
               (command "_.-export" "_PDF" "_C" "_NO" filename)
             )
           )
         )
         (setvar 'CTAB otab)
        )
  )
  (princ)
)

 

Edited by SLW210
Added Code Tags!
Link to comment
Share on other sites

15 hours ago, BIGAL said:

Yes can be done. If need more help just post

 

Need to edit the plot lsp to suit your title block. Need to down load ghostscript and edit the code to suit its install location and version number.

 

Am I correct in remembering that with GhostScript you plot all the PDFs as individual files and then GhostScript collates them together as a single PDF? I usually just bombard the engineers with single PDFs so have never tried it before, back of my mind though says this.

 

Does GhostScript need a proper install or just saving to a folder somewhere - as time goes by we are getting locked down more and more as to what we can install happily.

 

 

I use a simple pop-up for PDFs, either click enter for PDF as-is, or 6 options to custom name the PDF (add suffix / prefix), save to desktiop (default for this is where the DWG is saved), PDF and e-mail via outlook, suffix with a time stamp or with a layout name plus plot at A3 or A4 to go in reports.

 

To plot all the sheets in a file I have a wrapper that loops sheet to sheet and runs the Plot_PDF Lisp on each, which might be something consider - get one routine working well and just use it again and again, 

 

Certainly possible

 

 

Link to comment
Share on other sites

We have used plot range for years very successfully, the bigegst for us was 88 layouts in one go, also had plot A1 and so on.

 

I have a sneaky idea Ghostscript writes to the registry, yes individual pdf files, you make a list of pdf files, and pass that list to Ghostscript. Just look at code.

 

I have moved Ghostscript on a disk but can not remember if it worked, if you can say install at home and copy from USB to drive C : or D and correct GS folder, try it. image.png.bd36ebec621501b14c9103504322f509.png

Edited by BIGAL
  • Like 1
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...