Author Topic: Help with printing menu  (Read 2473 times)

0 Members and 1 Guest are viewing this topic.

KHoughton

  • Guest
Help with printing menu
« on: April 23, 2014, 11:02:48 AM »
I have created a custom printing menu that allows the user to simply click on a button and print to a desired printer using a specific page setup defined in the drawing bypassing the plot dialog. Everything works fine except when trying to print a PDF file using the AutoCAD supplied DWG to PDF.pc3 file. The command executes completely without error but it does not prompt for a file name (as it does when you use the plot dialog) for the PDF and saves the PDF to a random folder. I am able to use the exact same command using the Adobe print driver and it does prompt for the file name, unfortunately my company wants both options but I cannot figure out a solution and users are complaining that they can’t find the PDF they just created. Any help or ideas on how to improve this code are greatly appreciated.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:24x36DWGPDF () (command "plot" "n" "" "24x36 - DWG TO PDF" "" "" "n" "y")) ;DWG to PDF File

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Help with printing menu
« Reply #1 on: April 23, 2014, 05:58:23 PM »
Have you tried using a detailed plot configuration?

e.g.:
Code - Auto/Visual Lisp: [Select]
  1.     "_.-plot"
  2.     "_Y" ;; Detailed plot configuration? [Yes/No]:
  3.     ""   ;; Enter a layout name <Current-Layout>:
  4.     "dwg to PDF" ;; Enter an output device name:
  5.     "ANSI full bleed B (11.00 x 17.00 Inches)" ;; Enter paper size:
  6.     "_I" ;; Enter paper units [Inches/Millimeters]:
  7.     "_L" ;; Enter drawing orientation [Portrait/Landscape]:
  8.     "_N" ;; Plot upside down? [Yes/No]:
  9.     "_E" ;; Enter plot area [Display/Extents/Limits/View/Window]:
  10.     "_F" ;; Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <1=1>:
  11.     "_C" ;; Enter plot offset (x,y) or [Center]:
  12.     "_Y" ;; Plot with plot styles? [Yes/No]:
  13.     "monochrome.ctb" ;; Enter plot style table name (enter . for none):
  14.     "_Y" ;; Plot with lineweights? [Yes/No]:
  15.     "_N" ;; Scale lineweights with plot scale? [Yes/No]:
  16.     "_N" ;; Plot paper space first? [Yes/No]:
  17.     "_N" ;; Hide paperspace objects? [Yes/No]:
  18.     (strcat  ;; Enter file name:
  19.         (getvar 'dwgprefix)
  20.         (cadr (fnsplitl (getvar 'dwgname))) "-" (getvar 'ctab) ".pdf"
  21.     )
  22.     "_N" ;; Save changes to page setup [Yes/No]:
  23.     "_Y" ;; Proceed with plot [Yes/No]:
  24. )

KHoughton

  • Guest
Re: Help with printing menu
« Reply #2 on: April 23, 2014, 06:12:17 PM »
It works but still does not prompt for the file name or location to save the file.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Help with printing menu
« Reply #3 on: April 23, 2014, 06:19:03 PM »
It works but still does not prompt for the file name or location to save the file.

In the example, I have automatically supplied the drawing filename & layout as the PDF filename - replace the strcat expression with "\\" or the pause symbol to prompt the user.

KHoughton

  • Guest
Re: Help with printing menu
« Reply #4 on: April 24, 2014, 10:20:45 AM »
The code you provided works great but ideally I would like a dialog to pop up so the user can choose the location to save the file or at the very least force AutoCAD to save the file in the same folder as the current drawing file.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Help with printing menu
« Reply #5 on: April 24, 2014, 10:45:47 AM »
Perhaps the first thing you should do is display the file dialog box and prompt the user for a save location and then take the result of that location and place it into the code that Lee showed.  I believe that the getfiled command will bring up the file save dialog.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

KHoughton

  • Guest
Re: Help with printing menu
« Reply #6 on: April 24, 2014, 12:25:40 PM »
Got it! Thank you guys for your help, I greatly appreciate it. Although this routine prompts to save the file to the default folder with the default file name I wanted the ability to change the target folder and add a revision to the file name if needed.

Here's what I ended up with.
Code - Auto/Visual Lisp: [Select]
  1. (defun C:24x36DWGPDF () (command "plot" "n" "" "24x36 - DWG TO PDF" "" (getfiled "Save PDF" "" "pdf" 1) "n" "y")) ;DWG to PDF File

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Help with printing menu
« Reply #7 on: April 24, 2014, 02:09:25 PM »
You're welcome  :-)

As Keith has suggested, I would also recommend prompting before issuing the PLOT command to account for a null user input:
Code: [Select]
(defun c:24x36DWGPDF ( / pdf )
    (if (setq pdf (getfiled "Save PDF" "" "pdf" 1))
        (command "_.-plot" "_n" "" "24x36 - DWG TO PDF" "" pdf "_n" "_y")
    )
    (princ)
)

KHoughton

  • Guest
Re: Help with printing menu
« Reply #8 on: April 24, 2014, 02:19:11 PM »
You're welcome  :-)

As Keith has suggested, I would also recommend prompting before issuing the PLOT command to account for a null user input:
Code: [Select]
(defun c:24x36DWGPDF ( / pdf )
    (if (setq pdf (getfiled "Save PDF" "" "pdf" 1))
        (command "_.-plot" "_n" "" "24x36 - DWG TO PDF" "" pdf "_n" "_y")
    )
    (princ)
)

Thank you Lee, that works great!