Saving PDF from Python script. No raster?

Is there a way to get the surfaces to print? Also, if there is a way for me to save the file without having the save dialog pop up and having to click ok it would be helpful. Here is the script. Thanks!

pdf = Rhino.FileIO.FilePdf.Create()
dpi = 300
size = System.Drawing.Size(11*dpi,8.5*dpi)
pageToAdd = Rhino.Display.ViewCaptureSettings(sc.doc.Views.ActiveView, size, dpi)
pdf.AddPage(pageToAdd)

infoForFile = "{}.pdf".format(y)
filename = rs.SaveFileName(False, False, cadFileLocation, infoForFile, '.pdf')
pdf.Write(filename)

Hi John,

Without an example file or complete script it’s not easy to find what you are missing in the output.
As for the popup:

for pdf.Write(filename) you can pass the full path for the pdf, there is no need for the rs.SaveFileName

Does this make sense?
-Willem

Here is the full script. Takes selected items and for each group makes a bounding box and outputs box dimensions with PDF screen shot.

my test script.py (3.1 KB)

Here is a screen shot of my CAD file and the PDF it outputs


5.pdf (111.8 KB)

Hi John,

I think it best for @stevebaer to chime in and tell if this is expected behaviour an/or how to make sure the
Rhino.Display.ViewCaptureSettings are capturing to the shaded mode.

The view in in shaded mode yet the PDF is created in wireframe.

John: As a test: What happend is you set the vie to rendered mode

-Willem

Here is an output in rendered mode. Looks like it leaves out the rasters
test.pdf (276.7 KB)

In my experience with just normal printing (not via script) if the output in the print dialog is set to vector mode, a print to PDF will always be wireframe. You have to make sure the output is set to raster mode to get shaded surfaces. Maybe you need to do that script-wise as well…

Now that I mess with it more it appears to be something with the “save as” PDF function. If I do a normal “save as” and choose PDF then select the raster function it previews just fine but when I actually save it the surfaces are not there. If I turn on “Background Color” under “Visibility” then everything comes through.

background off.pdf (268.4 KB)
background on.pdf (153.4 KB)

Any ideas?

There isn’t a great way to do this at the moment. I added an issue to our bugtracking system to add this option in ViewCaptureSettings
https://mcneel.myjetbrains.com/youtrack/issue/RH-52318