Layout SaveAs PDF


#1

I am attempting to batch export layouts as PDF’s. The following script almost works.

import rhinoscriptsyntax as rs
cmd="-_SaveAs "
cmd+="D:\Desktop\TestPDF.pdf "
cmd+="_Enter "
    
rs.Command(cmd)

The issue I am having is I cannot get past SaveAs pdf window that pops up, I can change the default location of file but I still have to hit enter everytime.

I have looked into using ctypes to simulate keystrokes but have not had much success.
Could something in System.Windows.Forms maybe be used for to press the [Enter] key at the end of the script?

Thanks,
5chmidt


#2

Here is current what I wrote and use.

def BatchPrint():
fileNames= rs.OpenFileNames("Pick Files To Print","RhinoFile(*.3dm)|*.3dm||")

for a in fileNames:
    Rhino.RhinoDoc.OpenFile(a)
    LayoutNames=scriptcontext.doc.Views.GetPageViews()
    LayName = LayoutNames[0]
    rs.CurrentView(LayName.PageName)
    rs.Command("_-Print G")

The way I do it is print one page with correct page setups settings/pdf driver. Then Rhino will remember those for all the other prints it makes. Also I only 1 layout in made files so the scirpt is set up to switch to the only layout in the file. If you have more than one you may need to tweek it.


#3

you could also try it like this. It what I have in another script to batch export/save as dwg files.

rs.Command("!_-SaveAs " + newpath + " _Enter")

newpath = a string I defined earlier in the script for the location and file name.


#4

Thanks for the replies. Unfortunately, I don’t think either of these address my current issue. When I attempt to batch print to PDF I am always prompted with a popup window asking for the file location I to save the PDF at. I can change where what appears as the default path by passing it in as newpath in your script, but even including " _Enter"+" _Enter" I still have to press the [Enter] key to get through the pdf SaveAs dialog box.

Attached is an image of the dialog box I cannot seem to suppress.

Thanks,
5chmidt


#5

If the only way I can accomplish batch printing of PDFs is to press [Enter] for each one that is fine. However, it is not super convenient if I have to press [Enter] 50 or so times for a batch pdf export. If anyone has a solution for this it would be great.
Thanks,
5chmidt


#6

I have added:

import System

VK_RETURN="0x0D"

System.Windows.Forms.SendKeys.SendWait(VK_RETURN)

To the end of my code in an attempt to simulate pressing [Enter] to get through the SaveAs Dialog window. However, I have not had any success with it as of yet. Is there a better option for exporting a pdf within Rhino python?

Thanks,
5chmidt


#7

This may not be the solution you are looking for but with the PDF995 (paid for version) printer, there is a setting to bypass the dialog which allows the file name to be manipulated in your script. Maybe Acrobat has a similar setting.


#8

Brian,
Thanks for the replay. Your suggestion worked perfectly.
The settings for the Adobe PDF printer can be found in:

HKLM\SOFTWARE\Adobe\Acrobat Distiller<version>.

Additionally, the documentation is here:
http://www.adobe.com/devnet-docs/acrobatetk/tools/Wizard/pdfprinter.html

Thanks,
5chmidt


#9

Hi 5chmidt,

I was trying to do the same thing but I cannot get through the whole windows setting files changes. Could you explain to me step by step where and how to change the adobe pdf print settings as to suppress the dialogue box? It would be of great help!

Thanks,
Stefana


#10

I can tell you how to do it for Windows, its probably different if you are running a Mac.

1 - Click Start Menu
2 - Devices and Printers
3 - Right Click Adobe PDF Printer
4 - Click Printing Preferences
**I no longer have Adobe so I’m going from memory for the last bit here
5 - Change “Prompt for Adobe PDF Filename” to the folder you want Adobe to dump your PDFs by default.

It will now place every pdf you create into your specified dump folder.
You can move them around to your desired final location using:

import os
os.rename("C:\current_location.pdf","C:\desired_destination.pdf")

Hope that helps,
5chmidt


#11

Thanks a lot! That is working perfectly!

Stefana