Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export to PDF Lisp Routine

48 REPLIES 48
Reply
Message 1 of 49
kethridge21
6363 Views, 48 Replies

Export to PDF Lisp Routine

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.

48 REPLIES 48
Message 2 of 49
hmsilva
in reply to: kethridge21


@kethridge21 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

Message 3 of 49
Jonathan3891
in reply to: hmsilva

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
Message 4 of 49
kethridge21
in reply to: hmsilva

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.

Message 5 of 49
kethridge21
in reply to: Jonathan3891

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

Message 6 of 49
hmsilva
in reply to: kethridge21


@kethridge21 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

Message 7 of 49
kethridge21
in reply to: hmsilva

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

 

Message 8 of 49
hmsilva
in reply to: kethridge21


@kethridge21 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

Message 9 of 49
kethridge21
in reply to: hmsilva

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?

Message 10 of 49
hmsilva
in reply to: kethridge21


@kethridge21 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

Message 11 of 49
kethridge21
in reply to: hmsilva

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

Message 12 of 49
hmsilva
in reply to: kethridge21


@kethridge21 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

Message 13 of 49
kethridge21
in reply to: hmsilva

Here you go. Back saved to 2010. Thanks.

Message 14 of 49
hmsilva
in reply to: kethridge21

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

Message 15 of 49
kethridge21
in reply to: hmsilva

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

Message 16 of 49
hmsilva
in reply to: kethridge21


@kethridge21 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

Message 17 of 49
hmsilva
in reply to: kethridge21

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

Message 18 of 49
kethridge21
in reply to: hmsilva

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!

Message 19 of 49
hmsilva
in reply to: kethridge21


@kethridge21 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

Message 20 of 49
dizon.cad
in reply to: hmsilva

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

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost