Export to PDF Lisp Routine

Export to PDF Lisp Routine

Anonymous
Not applicable
8,926 Views
48 Replies
Message 1 of 49

Export to PDF Lisp Routine

Anonymous
Not applicable

I'm looking for a Lisp Routine that will allow me to export drawings to pdf's. Futhermore, the file name needs to be generated from the information in the title block attributes i.e. drawing number (1st 5 digits), sheet number (next 4 digits), revision number (next 2 digits), & sheet size (last character). For instance, 123-45678-0101-01-C. Also, I would like for it to be saved in a specific location & before it is saved, I would like to enter a folder name. Can anybody get me started. It seems simple but I'm not sure if I could start it from scratch. I would prefer, if someone already had a Lisp Routine that was similar to this so I could just edit it.

0 Likes
8,927 Views
48 Replies
Replies (48)
Message 41 of 49

hmsilva
Mentor
Mentor

Hello Koya,

 

TRN1003-(1)

change

(setq name (strcat name "-" (cdr a)))
;to
(setq name (strcat name "-(" (cdr a) ")"))

TRN1003-Rev1

 

change

(setq name (strcat name "-" (cdr a)))
;to
(setq name (strcat name "-Rev" (cdr a)))

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 42 of 49

Anonymous
Not applicable

Hello, 

 

i'm having a slight issue with my routine: during the export command, i get a pop up asking to enter break loop for c:dd (image attached). Any way to avoid that?

 

(defun C:PDFEXPORT(/ strWO str filename)
  (vl-load-com)
  (setq strWO(getstring T "\n Enter Work Order Number: "))
  (setq str(getstring T "\n Plat | Electric | Gas: "))
  (setq filename(strcat "//corpnas01a/MapData/ImageSiteAcquire/Designs/AUD-Generated " str "_" strWO ".pdf"))
  (command "_.-export" "_PDF" "_A" filename)
)

 

 

0 Likes
Message 43 of 49

Jason.Rugg
Collaborator
Collaborator

@Jonathan3891  How can I make this code automatically set the export pdf filename to be the same as the current dwg filename?

 

Also, would it be possible to make the lisp allow you to select a list of dwg's and batch pdf them?

 

Thanks,

Jason

0 Likes
Message 44 of 49

Jonathan3891
Advisor
Advisor

@Jason.Rugg   

This will get set the filename the same as the dwg name

(if (setq filename (getfiled "enter actobat file name" "" "pdf" 1))
 (progn

Then use the variable "filename" in the plot configuration, like this

(command "-plot" "Y" "" "Dwg To PDF.pc3" "ANSI expand B (11.00 x 17.00 Inches)" "I"
"" "N" "E" "1:1" "" "Y" "ENTER PLOT STYLE" "Y" "N" "N" "N" filename "Y" "Y") ))

Have you looked at the PUBLISH command? It will allow you to batch plot multiple drawings. If that's not what your looking for check out Hurricane.

 

 

 


Jonathan Norton
Blog | Linkedin
0 Likes
Message 45 of 49

Jason.Rugg
Collaborator
Collaborator

Thanks, I guess I asked my question wrong, that does automatically set the filename. Can that be done so it doesn't open the saveas dialog box or can the lisp automatically save and close the dialog box?

0 Likes
Message 46 of 49

Jason.Rugg
Collaborator
Collaborator

@Jonathan3891 Below is the code I am using now. It is picking up the current filename and save location and after I click save it runs through the print and then at the end opens a second SaveAs dialog box and asks me to save but I have to manually set the filename to the current filename and the original file location.

 

I need both saveas dialog boxs to automatically have the current filename as the filename and save to the current file location and close the boxes automatically. Hopefully that makes sense. 

 

(defun c:PDF(/)
(if (setq filename (getfiled "Enter Filename" "" "pdf" 1))
(progn

(command "tilemode" "0")
(command "-plot" "Yes" "" "CutePDF Writer.pc3" "Ledger" "Inches"
"Landscape" "N" "Extents" "Fit" "Center" "Yes" "KCI-monochrome.ctb" "No" "No" "No" "No" "No" "No" "Yes" filename "" ) ))
(princ) )

0 Likes
Message 47 of 49

Jason.Rugg
Collaborator
Collaborator

@Jonathan3891 I was able to figure out that once I switched the .pc3 from CutePDF Writer and back to DWG To PDF I don't get the second SaveAs dialog box, so this is perfect but I just need the initial filename dialog box to automatically save and close itself without interaction. Is this possible? If so this is all I need and I can make my batch process work. Code now looks like this again:

 

(defun c:PDF(/)

(if (setq filename (getfiled "Enter Filename" "" "pdf" 1))
(progn

(command "tilemode" "0")
(command "-plot" "Yes" "" "DWG To PDF.pc3" "ANSI full bleed B (11.00 x 17.00 Inches)" "Inches"
"Landscape" "No" "Extents" "Fit" "Center" "Yes" "KCI-monochrome.ctb" "No" "No" "Yes" "No" filename "No" "Yes" ) ))
(princ) )

0 Likes
Message 48 of 49

krazeymike
Enthusiast
Enthusiast

Hi Henrique, This is so cool.

 

I was wondering is it possible to tweak this code (Message No. 6) 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

 

I normally use publish with the current layout to pdf and either drop layouts if not required or save multiple layouts as a single pdf. It would be so cool to have this process automated in a lisp routine. I love the directory prompt in your original code.

 

Your Original Code

(vl-load-com)
(defun c:demo (/ 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)
)

 

0 Likes
Message 49 of 49

maratovich
Advisor
Advisor

If you find it difficult to modify Lisp to suit your needs, it may be easier to use a generic solution.

There is a ready-made solution that allows you to do what you need - Revers 

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