Print Layouts to PDFs - One layout to one PDF?

When Rhino prints layouts to PDF, all layouts are printed in a single PDF.

i want to print layouts to PDF’s separately, one layout to one PDF in a defined folder. The PDF’s use layout names.

it should be automatic, because i have 100 Layouts, and i change mein model very often.
i mean, if i chang my model, i must overwrite the 100 pdfs one time.

someone had idea? it will be very very helpful.

1 Like

I added an item to the wish list for future development:
https://mcneel.myjetbrains.com/youtrack/issue/RH-37263

This should be possible now with a custom python script.

@Ning_Zhang, here’s the script written by @JorinChi .

Create C:\pdf_output\ before using the script.

Select Tools > PythonScript > Run and select the 1Layout1PDF.py to run.

1Layout1PDF.py (506 Bytes)

1 Like

Oh this is great Kelvin!
Just one question…is there a way to change output from vector to raster? I’ve been looking at ViewCaptureSettings but nothing there

Not yet; this is still on my list of features to add to the expoter.

Snap…any temporary workaround? It’s just my models are displayed as Shaded in the layout but in pdf I get Wireframe

Just the long handed approach of printing individual pages with the print dialog.

What is the equivalent in c#?

I am getting the following error when trying with Rhino 5 SR14:

Message: ‘namespace#’ object attribute ‘FilePdf’ is read-only

This functionality does not exist in Rhino 5. It is a new feature in Rhino 6

I see. Thanks for clarifying.

@KelvinC @JorinChi @stevebaer

thank you so much. it works good!
i have one question, i can change the PDF Size manually, if i have all layouts in A4 or A3, or A2…
but what happend if i have different Layoutsize, for example, i have 2X A4, 3XA3, 4XA0…

can you change the script that it automatically get the layousize? it will very helpful.

thank you very much.

"
import Rhino
import scriptcontext as sc
import System.Drawing
import rhinoscriptsyntax as rs

def createSinglePDF(view):
pdf = Rhino.FileIO.FilePdf.Create()
dpi = 300
size = System.Drawing.Size(8.5dpi,11dpi)
settings = Rhino.Display.ViewCaptureSettings(view, size, dpi)
pdf.AddPage(settings)
filename = ‘c:/pdf_output/’+view.PageName+’.pdf’
pdf.Write(filename)

for i in sc.doc.Views:
if type(i) is Rhino.Display.RhinoPageView:
createSinglePDF(i)

"
grafik

@JorinChi, Can you take a look? Thanks.

PageView has a “PageWidth” and “PageHeight” property so it should be possible to redefine “size” every iteration. If you are familiar with scripting this shouldn’t be too hard, if not you would have to wait a bit, not on a PC right now

This seems to be working, though i’m having trouble how to set up dpi if the pageunitsystem is not in inches but rather in mm, like it is typically done around here in europe…
maybe someone has more knowledge in that part? right now i’m just multiplying by a factor i found on the internet. That gives linewidths that are a bit too thick, anyways here is the code


import Rhino
import scriptcontext as sc
import System.Drawing
import rhinoscriptsyntax as rs

def createSinglePDF(view):
    # converts millimeters to inch, because DPI is "DotsPerInch"
    # 1 dot/inch [dpi] = 0.0393700787401575 dot/millimeter [dot/mm]
    if sc.doc.ActiveDoc.PageUnitSystem == sc.doc.PageUnitSystem.Millimeters:
        factor = 0.0393700787401575
        
    else:
        factor = 1.0
                
    # create pdf object
    pdf = Rhino.FileIO.FilePdf.Create()
    
    # hardcoded dpi
    dpi = 600
    
    # create size from pageWidth / height, our factor and dpi
    size = System.Drawing.Size(view.PageWidth * factor * dpi, view.PageHeight * factor * dpi)
    
    # create settings
    settings = Rhino.Display.ViewCaptureSettings(view, size, dpi)
    
    # add one page to our pdf object containing the layout
    pdf.AddPage(settings)
    
    # create our filename
    filename = "c:/pdf_output/" + view.PageName + ".pdf"
    
    # and finally write to file
    pdf.Write(filename)

for view in sc.doc.Views:
    if type(view) is Rhino.Display.RhinoPageView:
        createSinglePDF(view)

Hi,

If you will always be using mm you can hardcore the conversion by converting mm to inches

size = (mm/25.4 ) *dpi EDIT should be 25.4

Does that make sense?
-Willem

Hey Willem,
Yes that makes sense as 1/25,5 = 0.0393700787401575 ca.

I still don’t understand why dpi so drastically influence line thickness especially when going higher than around 2k dpi all the lines become dotted. This might be the inner workings of the pdf class in rhino or maybe the pdf format itself

thanks all! i got a finish Script from meine colleague.:slight_smile:
it works fine.


import Rhino
import scriptcontext as sc
from scriptcontext import doc
import System.Drawing
import rhinoscriptsyntax as rs

def createSinglePDF(view):
    pdf = Rhino.FileIO.FilePdf.Create()
    dpi = 300
    inch = 25.4
    width = (view.PageWidth)/inch
    height = (view.PageHeight)/inch
    size = System.Drawing.Size(width*dpi,height*dpi)
    settings = Rhino.Display.ViewCaptureSettings(view, size, dpi)
    pdf.AddPage(settings)
    filename = 'c:/pdf_output/'+view.PageName+'.pdf'
    pdf.Write(filename)


for i in sc.doc.Views:
    if type(i) is Rhino.Display.RhinoPageView:
        createSinglePDF(i)
2 Likes

hello lando, can you tell me, how to post the script like this?


thanks!