Export to PDF Lisp Routine

Export to PDF Lisp Routine

Anonymous
Not applicable
8,864 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,865 Views
48 Replies
Replies (48)
Message 2 of 49

hmsilva
Mentor
Mentor

@Anonymous wrote:

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.


Hi kethridge21,

one doubt,

'drawing number (1st 5 digits)' >>>> '123-45678'not 5 digits...

Do you mean the first digits came from the 'drawing number tag? Regardless the number of digits?

 

Henrique

 

EESignature

0 Likes
Message 3 of 49

Jonathan3891
Advisor
Advisor

See if this will work for you or will get you started in the right direction.

 

It will name the pdf the dwg file name. You only have to specify where you want to save the PDF.

 

Just make sure to list your plot style where I put "ENTER PLOT STYLE" for it to work correctly.

 

(defun c:PDF(/)

;; make sure filename is ok before plotting

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

(command "tilemode" "0")
(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") ))
(princ) )

 


Jonathan Norton
Blog | Linkedin
0 Likes
Message 4 of 49

Anonymous
Not applicable

Yes Henrique. The 1st 8 digits come from the drawing number tag, in the title block attributes. The next 4 digits would come from the sheet number tag in the title block, & the next 2 digits would come from the revision number tag in the title block. Finally, the last "alpha" character would come from the sheet size tag in the title block.

0 Likes
Message 5 of 49

Anonymous
Not applicable

Cool. Thank you DSM_dude. Will try in the morning & let you know how it turns out.

0 Likes
Message 6 of 49

hmsilva
Mentor
Mentor

@Anonymous wrote:

Yes Henrique. The 1st 8 digits come from the drawing number tag, in the title block attributes. The next 4 digits would come from the sheet number tag in the title block, & the next 2 digits would come from the revision number tag in the title block. Finally, the last "alpha" character would come from the sheet size tag in the title block.


Hi kethridge21,

you'll have to change (2 . "title_block_name") to the correct block name, and ("DRAWING_NUMBER" "SHEET_NUMBER" "REVISION_NUMBER" "SHEET_SIZE") to the correct TAG's.

 

(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)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 7 of 49

Anonymous
Not applicable

You guys are awsome. Thank you for your help. What command executes this lisp?

 

0 Likes
Message 8 of 49

hmsilva
Mentor
Mentor

@Anonymous wrote:

You guys are awsome. Thank you for your help. What command executes this lisp?


You're welcome, kethridge21
The command is demo

Henrique

EESignature

0 Likes
Message 9 of 49

Anonymous
Not applicable

Hey Henrique, just got through trying out the lisp. I set the variables for the title block & for the rest of the tags in the title block. For some reason, it saves it as a dwl file. How I get it to save it as a pdf?

0 Likes
Message 10 of 49

hmsilva
Mentor
Mentor

@Anonymous wrote:

Hey Henrique, just got through trying out the lisp. I set the variables for the title block & for the rest of the tags in the title block. For some reason, it saves it as a dwl file. How I get it to save it as a pdf?


HI kethridge21,

 

the

(command "_.-export" "_PDF" "_C" "_NO" filename)

should export each layout as .pdf file...

Tested in 2010 and 2014...

Try to change this code line to

(command "_.-export" "Pdf" "_C" "_NO" filename)

and see if it works as expected

 

Henrique

 

EESignature

0 Likes
Message 11 of 49

Anonymous
Not applicable

Running 2015.....The highlighted lines are the only lines that I've edited. Please take a look & see if anything looks funny. It acts like it's doing something but nothing gets saved. I point it to the folder that I want it to be saved in but it doesn't get saved.

 

 

Lisp_Capture.PNG

0 Likes
Message 12 of 49

hmsilva
Mentor
Mentor

@Anonymous wrote:

Running 2015.....The highlighted lines are the only lines that I've edited. Please take a look & see if anything looks funny. It acts like it's doing something but nothing gets saved. I point it to the folder that I want it to be saved in but it doesn't get saved.


kethridge21,

could you please attach a sample dwg with one or two blocks in AC2010 (I'm in holidays, and I only have an old laptop with AC2010...)

 

Henrique

EESignature

0 Likes
Message 13 of 49

Anonymous
Not applicable

Here you go. Back saved to 2010. Thanks.

0 Likes
Message 14 of 49

hmsilva
Mentor
Mentor
Do you need to save as.pdf just the Model space?
The code was written to save as .pdf all layouts (paper spaces)...

Henrique

EESignature

0 Likes
Message 15 of 49

Anonymous
Not applicable

Oh yeah...model space. I don't even use paper space if I can help it. Does that make a difference?

0 Likes
Message 16 of 49

hmsilva
Mentor
Mentor

@Anonymous wrote:

Oh yeah...model space. I don't even use paper space if I can help it. Does that make a difference?


Yes.

In paper space, the plot configurations are set in the page setup, and with the command 'export', we only need to use the Current Layout configuration to plot...

In Model space, we can't use the Current Layout configuration, probably we'll have to plot to .pdf...

Tomorrow I'll see what I can do.

 

Henrique

EESignature

0 Likes
Message 17 of 49

hmsilva
Mentor
Mentor

Hi kethridge21,

 

inches and feet, are not my world, I'm a metric guy...

As a starting point...

(defun c:demo (/ hms:get_atts filename hnd layouts 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")
      )
    )
  )

  (if (and (setq path (acet-ui-pickdir "Select directory" (getvar "dwgprefix")))
           (setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "BBORDER") '(66 . 1) (cons 410 (getvar 'CTAB)))))
      )
    (progn
      (setq hnd  (ssname ss 0)
            lst  (hms:get_atts hnd)
            lst1 '("DWG#" "SHT" "REV#" "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" "_E" "_NO" filename)
    )
  )
  (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 18 of 49

Anonymous
Not applicable

Perfect. Thanks you for your help! I guess I have to set the plot screen up first & "apply to layout" if I want it to use my plot style & plot settings. This is not a big deal though since most of the drawings should already have these settings set. Cool!

0 Likes
Message 19 of 49

hmsilva
Mentor
Mentor

@Anonymous wrote:

Perfect. Thanks you for your help! I guess I have to set the plot screen up first & "apply to layout" if I want it to use my plot style & plot settings. This is not a big deal though since most of the drawings should already have these settings set. Cool!


You're welcome, kethridge21
Glad I could help!

 

Yes, you'll have to set the plot first.

You may change the '-export' command, to '-plot 'command, and enter the plot settings during the command...

Henrique

EESignature

0 Likes
Message 20 of 49

Anonymous
Not applicable

hey Henrique,

 

Thank you for your expertise,, You are AWESOME,

 

Just extra queries,

 

- how do I specify a default pdf output folder?

 

- and rather than seperating the attributes values in ' - ' (dash) in your pdf name, how can you separate the values in ' _ " (under score)  ?

 

Thanks again,

Koya

 

 

0 Likes