Author Topic: How to save a PDF file thru running a script  (Read 6796 times)

0 Members and 2 Guests are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
How to save a PDF file thru running a script
« on: April 17, 2015, 11:47:06 AM »
I am running a script and cannot get past the saving a PDF file without an enter thru the saveas dialog box. I have tried everything. Everything works except I have the "Save PDF File As" dialog box pop up. I have even tried (command) as part of the script.

Please help.






This is part of the plotscript:

(setvar "FILEDIA" 0)
_.open "F:\Jobs\2014\140310\ACAD\A0-00.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
_.open "F:\Jobs\2014\140310\ACAD\A0-01.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
_.open "F:\Jobs\2014\140310\ACAD\A0-01a.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
_.open "F:\Jobs\2014\140310\ACAD\A1-01.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close

This the lisp file run from the script:
;DESCRIPTION:PDFPlot
;***************************


(vla-put-DefaultPlotToFilePath (vla-get-output (vla-get-preferences (vlax-get-acad-object))) (getvar "dwgprefix"))
(command ".qsave")
(command ".zoom" "e" "limits" "off")
(command ".plot" "y" "fullsize" "GDF_Adobe PDF.pc3" "Arch D" "i" "l" "n" "w" "0,0" "36,24" "f" "center" "y" "aia standard.ctb" "y" "y" "n" "n" "n" "n" "y")

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How to save a PDF file thru running a script
« Reply #1 on: April 17, 2015, 12:35:03 PM »
Any reason you're not using sheet set manager or publish ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: How to save a PDF file thru running a script
« Reply #2 on: April 17, 2015, 12:47:16 PM »
Never used them.

Just trying to figure out why the dialog box keeps popping up and the newly created PDF file does to close once created. I guess its beyond what script file and lisp can do.

Thanks
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How to save a PDF file thru running a script
« Reply #3 on: April 17, 2015, 01:00:56 PM »
Never used them.

Just trying to figure out why the dialog box keeps popping up and the newly created PDF file does to close once created. I guess its beyond what script file and lisp can do.

Thanks
They would make your life much easier. :) ..

On a quick test, FILEDIA set to 0 suppresses the dialog box here. Do you have something that changes variables on startup?

Maybe try putting the (setvar "filedia" 0) in your lisp ?
Code - Auto/Visual Lisp: [Select]
  1. (vla-put-defaultplottofilepath
  2.   (getvar "dwgprefix")
  3. )
  4. (command ".qsave")
  5. (command ".zoom" "e" "limits" "off")
  6. (setvar 'filedia 0)
  7. (command ".plot"     "y"    "fullsize"  "GDF_Adobe PDF.pc3"     "Arch D"    "i"
  8.     "l"        "n"    "w"        "0,0"    "36,24"     "f"    "center"
  9.     "y"        "aia standard.ctb"        "y"    "y"        "n"    "n"
  10.     "n"        "n"    "y"
  11.    )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: How to save a PDF file thru running a script
« Reply #4 on: April 17, 2015, 01:26:56 PM »
Thanks

Still getting the dialog box. See pic.

It takes an enter to clear the popup...
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Peter2

  • Swamp Rat
  • Posts: 653
Re: How to save a PDF file thru running a script
« Reply #5 on: April 17, 2015, 02:56:38 PM »
Where does the dialogue comes from? It seems to me that the dialogue is invoked by your PDF-driver (Adobe?) and not by AutoCAD. have you checked all your PDF-settings for something like "automated saving versus Show dialogue"?"
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

trogg

  • Bull Frog
  • Posts: 255
Re: How to save a PDF file thru running a script
« Reply #6 on: April 17, 2015, 03:14:59 PM »
Here are the LISP routines and script file that I use to print to PDF in one click.

This one works for Model Space:
Code: [Select]
;;; http://www.theswamp.org/index.php?topic=39461.0;all
;;; Lee-Mac
(defun c:2PDF ( / cm )
(vl-load-com)
    (setq cm (getvar 'CMDECHO))
    (setvar 'CMDECHO 0)
    (command "_.-plot" "_y"
        (if (= 1 (getvar 'TILEMODE)) "Model" (getvar 'CTAB))
        "DWG To PDF.pc3" "ANSI full bleed B (11.00 x 17.00 Inches))"
        "_I" "_L" "_N" "_E" "_F" "_C" "_Y" "monochrome.ctb" "_Y"
    )
    (if (= 1 (getvar 'TILEMODE))
        (command "_A")
        (command "_N" "_Y")
    )
    (command "_N" (strcat (getvar 'DWGPREFIX) (vl-filename-base (getvar 'DWGNAME))) "_Y" "_Y")
    (setvar 'CMDECHO cm)
    (princ)
)
(vl-load-com) (princ)

And this one works for the current Paper Space layout. The lisp code at the begining staroes the file name and uses that to name the PDF instead of AutoCAD including the name of the layout tab in the name of the PDF.
Note: this is a script file
Code: [Select]
(setq CurrDwgName (getvar "dwgname"))
(setq Fname (substr CurrDwgName 1 (- (strlen CurrDwgName) 4)))
(setq name (strcat (getvar "DWGPREFIX") Fname ".pdf"))
;Command:
FILEDIA
;Enter new value for FILEDIA <1>:
0
;Command:
-PLOT
;Detailed plot configuration? [Yes/No] <No>:
Y
;Enter a layout name or [?] <Model>:

;Enter an output device name or [?] <None>:
DWG To PDF.pc3
;Enter paper size or [?] <ANSI A (11.00 x 8.50 Inches)>:
ANSI full bleed B (11.00 x 17.00 Inches)
;Enter paper units [Inches/Millimeters] <Inches>:
Inches
;Enter drawing orientation [Portrait/Landscape] <Portrait>:
Landscape
;Plot upside down? [Yes/No] <No>:
No
;Enter plot area [Display/Extents/Layout/View/Window] <Display>:
e
;Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <Fit>:
f
;Enter plot offset (x,y) or [Center] <0.00,0.00>:
C
;Plot with plot styles? [Yes/No] <Yes>:
Yes
;Enter plot style table name or [?] (enter . for none) <>:
monochrome.ctb
;Plot with lineweights? [Yes/No] <Yes>:
Y
;Plot Scale lineweights with plot scale? <No>

;Plot paper space first? <No>

;Hide paper space objects? <No>

;Enter file name <Something.pdf>:
!name
;Save changes to page setup? Or set shade plot quality? [Yes/No/Quality] <N>:
No
;Proceed with plot [Yes/No] <Y>:
Yes
;Command:
FILEDIA
;;;Enter new value for FILEDIA <1>:
1


This LISP will print all layout tabs as individual PDFs.
Code: [Select]
;; Prints All Layout Tabs and names the new PDFs with the name of the
;; drawing followed by the layout tab name.
;;
;; Adjust the paper size and .ctb file as needed.
;;
;; The PDFs will be placed in the folder where the drawing resides
;;
(defun c:PA ()
(foreach lay (layoutlist)
  (setvar 'CTab lay)
  (COMMAND "-PLOT"
"Y"
""
"DWG To PDF.pc3"
"ANSI full bleed B (11.00 x 17.00 Inches)"
"Inches"
"Landscape"
"N"
"E"
"f"
"C"
"Y"
"monochrome.ctb"
"Y"
"N"
"N"
"N"
""; Name of file
"N"
"y"      )
    )
)

GDF

  • Water Moccasin
  • Posts: 2081
Re: How to save a PDF file thru running a script
« Reply #7 on: April 17, 2015, 04:24:44 PM »
Thanks guys.

Still cannot get the Adobe dialog box not to come up. I have been unsuccessful in finding the setting in Adobe, if it exists.

Thanks
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How to save a PDF file thru running a script
« Reply #8 on: April 17, 2015, 05:17:56 PM »
Thanks guys.

Still cannot get the Adobe dialog box not to come up. I have been unsuccessful in finding the setting in Adobe, if it exists.

Thanks
IMO .. You should really look into Sheet Set manager or Publish. Sheet set manager came out in 2005 and I haven't plotted with a script since :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: How to save a PDF file thru running a script
« Reply #9 on: April 17, 2015, 05:38:19 PM »
I know, we don't save the plot info in the drawing layout. We only use a script, so we can set up the parameters as need.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How to save a PDF file thru running a script
« Reply #10 on: April 17, 2015, 09:24:10 PM »
If you setup a template with named pagesetups (pagesetup overrides), you don't have to save anything in the drawing. Just select the setup, select your drawings and watch. :)  If you'd like further instruction on doing this let me know.
« Last Edit: April 17, 2015, 09:37:47 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Peter2

  • Swamp Rat
  • Posts: 653
Re: How to save a PDF file thru running a script
« Reply #11 on: April 18, 2015, 03:31:25 AM »
...  If you'd like further instruction on doing this let me know.
Yes - I'm interested on this method. Maybe you can create a Screencast?
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

GDF

  • Water Moccasin
  • Posts: 2081
Re: How to save a PDF file thru running a script
« Reply #12 on: April 18, 2015, 11:56:59 AM »
Thanks

I think the PDF switch for turning off the saveas dialog box is in the pc3 file
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: How to save a PDF file thru running a script
« Reply #13 on: April 19, 2015, 12:14:43 PM »
Ok, I found the switch within the pcs file and it fixed the dialog box opening problem!!!

Now I'm trying to set the path where the PDF files are saved. The following does not set the path:

(vla-put-DefaultPlotToFilePath (vla-get-output (vla-get-preferences (vlax-get-acad-object))) (getvar "dwgprefix"))


So what am I doing wrong?
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: How to save a PDF file thru running a script
« Reply #14 on: April 19, 2015, 01:43:10 PM »
Everything works now, except for saving the files to the current directory.




Create a new Adobe PDF for Batch Plotting PC3.
---------------------------------------------------------------------------

1. Create a new Adobe PDF for Batch Plotting PC3.
2. Type plot.
3. Select the new PC3.
4. Click on the Properties box to the right.
5. When the driver Dialog pops up Click on the Device and Document settings tab.
6. Half way down click on "Custom Properties."
7. Near the botton Click on the "Custom Properties" box that will appear.
8. A new dialog box titled "Adobe PDF Document Properties" will pop up.
9. Click on the "adobe PDF Settings" Tab.
10 You should see for setting with pulldowns to the right. Click on the third one down "Adobe PDF output Folder"
11. Select "My Documents\*.pdf"  (or create you own folder)

So it looks like you ownly have two options.
1) Selecting a custom folder to save the PDF files w/o the annoying dialog box
2) Have the dialog box pop up the select the saveas name and path.


This is my lisp file that is run from a batch script: (you can see everything that I have tried)
Note: I rename the layout to "." to only save the PDF file by the dwg name. (looking for a better solution here)
I have included the batch plot routine.


Code: [Select]

;DESCRIPTION:PDFPlot
;***************************

(vl-load-com)

(defun ARCH:PlotToFilePathSet (/ *acad prefs pprefs)
  (setq *acad (vlax-get-acad-object))
  (setq prefs (vla-get-preferences *acad))
  (setq pprefs (vla-get-output prefs))
  (vla-put-DefaultPlotToFilePath pprefs (getvar "dwgprefix"))
)
(defun ARCH:PlotToFilePathGet ()
  (vla-get-DefaultPlotToFilePath
    (vla-get-output
      (vla-get-preferences (vlax-get-acad-object))
    )
  )
)



;;(command "-psetupin" (strcat ARCH#CSTF "Acad.dwt") "*")
;;(vla-put-DefaultPlotToFilePath
;;    (vla-get-Output (vla-get-Preferences (vlax-get-acad-object)))
;;    (getvar "dwgprefix");;"E:\\Plot"
;;  )
;;(getenv "PlotToFilePath")(setenv "PlotToFilePath" "E:\\Plot")
;;(getenv "PlotToFilePath")
;;(setenv "PlotToFilePath" "C:\\Arch_Custom\\PDF")


(ARCH:PlotToFilePathSet)


(vlax-for
         layout  (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (setq name (vla-get-name layout))
    (progn (if (= name "FullSize")
             (vla-put-name layout "."))           ))
;;(setq CurrDwgName (getvar "dwgname"))
;;(setq Fname (substr CurrDwgName 1 (- (strlen CurrDwgName) 4)))
;;(setq name (strcat (getvar "DWGPREFIX") Fname ".pdf"))
(command ".qsave")
(command ".zoom" "e" "limits" "off")
;;(command ".plot" "y" "fullsize" "Adobe PDF.pc3" "Arch D" "i" "l" "n" "w" "0,0" "36,24" "f" "center" "y" "aia standard.ctb" "y" "y" "n" "n" "n" "n" "y")
(command ".plot" "y" "." "Adobe PDF.pc3" "Arch D" "i" "l" "n" "w" "0,0" "36,24" "f" "center" "y" "aia standard.ctb" "y" "y" "n" "n" "n" "n" "y")
(vlax-for
         layout  (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (setq name (vla-get-name layout))
    (progn (if (= name ".")
             (vla-put-name layout "FullSize"))
           ))


Here is the batch plot script that is written:

Code: [Select]

SDI 1
(setvar "FILEDIA" 0)
_.open "F:\Jobs\2013\131020\acad\A10-01.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
_.open "F:\Jobs\2013\131020\acad\A10-02.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
_.open "F:\Jobs\2013\131020\acad\A10-03.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
_.open "F:\Jobs\2013\131020\acad\A10-04.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
_.open "F:\Jobs\2013\131020\acad\A10-05.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
_.open "F:\Jobs\2013\131020\acad\A10-06.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
_.open "F:\Jobs\2013\131020\acad\A10-07.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
_.open "F:\Jobs\2013\131020\acad\A10-08.dwg"
(load "V:/ARCH/Custom_Architettura/PlotCFG/PDFPlot.lsp")
.qsave
_.close
(setvar "FILEDIA" 1)
SDI 0
(ARCH:BatchPlotMsg)
[\code]
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Peter2

  • Swamp Rat
  • Posts: 653
Re: How to save a PDF file thru running a script
« Reply #15 on: April 19, 2015, 03:26:06 PM »
Everything works now, except for saving the files to the current directory....
I don't know the Adobe driver, but the other drivers I know (PDF Creator; PDF XChange) handles nearly everything outside of AutoCAD (e.g. the dialogue). In many cases there is an extra dialogue / ini setting / registry setting which handles this. There are drivers which can be set to the default "use the path of the document" - and have problems if the the software does not pass the path to the driver. For me, I modify the saving-path via registry settings inside my Lisp.

I hope there is a Adobe-specialist who can tell you the way for Adobe, but as said before: I suppose the solution is not in AutoCAD, it is in the driver.
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23