Logo
Published on

Automated PDFs in AutoCAD

Authors
  • avatar
    Name
    Ben Gibb
    Twitter

It takes ~38 keystrokes and mouse clicks to create just ONE PDF in AutoCAD the conventional way. This is a lot of work for something done many times per day. I've created a LISP routine that reduces this to 4 keystrokes. FOUR!

Just type pdf and hit enter. That's it.

Here is the LSP code:


(defun c:PDF(/) ; This defines a new function named 'PDF' that takes no arguments (hence the /)
(setq curdate (strcat (substr (rtos (getvar "CDATE") 2 0) 1 4) "-" (substr (rtos (getvar "CDATE") 2 0) 5 2) "-" (substr (rtos (getvar "CDATE") 2 0) 7 2)))
(command "tilemode" "0") ; Sets the TILEMODE system variable to 0 which switches to Paper Space
(command
"-plot" ; Initiates the plot command
"y" ; The prompt is: Detailed plot configuration? [Yes/No] <No>
"" ; This is for the layout name. An empty string uses the current layout
"Dwg To PDF.pc3" ; This is the output device name. It is the pc3 file that controls the output settings
"ANSI expand B (17.00 x 11.00 Inches)" ; This is the paper size
"I" ; This is the paper units (Inches)
"" ; This is for the drawing orientation. An empty string uses the current setting
"N" ; This is for the plot upside down option. N = No
"e" ; This is for the plot area. e = Extents
"Fit" ; This is for the plot scale. 'Fit' fits the plot to the page
"" ; This is for the plot offset. An empty string centers the plot
"Y" ; This is for plotting with plot styles. Y = Yes
"" ; This is for the plot style table name. An empty string uses the current setting
"Y" ; This is for plotting with lineweights. Y = Yes
"N" ; This is for scaling lineweights according to the viewport scale. N = No
"N" ; This is for plotting paperspace last. N = No
"N" ; This is for hiding objects in paperspace. N = No
(strcat curdate "\_" (getvar "dwgname")); FILENAME
"y" ; This is for overwriting existing file. y = Yes
"Y" ; This is for proceeding with the plot. Y = Yes
)
)

How to use

  1. Copy the code above into a text file and save it as pdf.lsp in a location of your choice.
  2. In AutoCAD, type appload and hit enter.
  3. Navigate to the location of the pdf.lsp file and select it.
  4. Type pdf and hit enter.

This will create the PDF in the current directory of the .dwg file and save it with the filename but prepended with the current date (YYYY-MM-DD).

Potential Future Improvements

A for loop could be used to iterate through all layouts in the drawing and create a PDF for each one. This would be useful for drawings with multiple layouts or projects with multiple files.