Print Layouts from gh?

I have seen some posts on this, but not a lot of solutions. I am generating some layouts with Document User Text that I need to print from Grasshopper. Is there no “out of the box” solution for this? Ideally, it would:

  • allow file path & filename input (instead of standard print window)
  • allow multiple layouts to be exported at once, perhaps as a single PDF, but multiple is fine.
  • MUST be rasterized, since my layout uses some images.

Thanks in advance for any replies - I’m up against a deadline on this one.

dh

Hi @declan,

For starters, the Print command is scriptable. How far does this get you?

– Dale

i have made some components to help with this. I’ve never needed rasterized output but i’m sure that’s not too hard to add

I’ve consolidated some updates here which are an improvement. it’s still needlessly complex, but hope it helps you. I’ve been using this system to procedurally create a series of data derived drawings to aid engineers designing infrastructure. The python components have tooltip help so please refer to that.

So far this can:

  • create layouts and update them
  • add details to layouts
  • print layouts
  • list existing layouts
  • delete list of layouts (if you make a mistake it’s a pain to manually delete more than several layouts!)

There are a bunch of settings for details scale, and display mode and raster vs vector, which will sometimes not work. Views are currently only possible create plan (no perspective views etc)


layouts.gh (33.4 KB)

8 Likes

This is great - thanks @dharman !

1 Like

Hi @dharman , thanks for sharing this. What is your recommended suggestion to set a dpi of the printed layouts? I want to include an option to switch between high and lowres pdfs (in Raster mode)

PS: notice a small bug. If you have 2 pages and want to save one page as ‘vector’ and the other as ‘raster’, it saves the same file twice, once with both pages as vector and the overwrites the file with pages in ‘raster’ mode.

I’m glad you’ve found some use for this, however Im not going to have a chance to revisit it for some time. I’d suggest having a look at the python code in the nodes by double clicking on the middle of the node. There will be something called dpi or resolution somewhere. I can’t remember how it works. You can create a new input on the node to expose the value. I believe it is hardcoded somewhere.

As for mixing vector and raster in the same output I’ve never needed this functionality so I’d consider it a feature request rather than a bug. It will need some additional code to allow a list of inputs

Thx, found it, easy adjustment.

I’ll see if I can resolve that minor vector/raster issue, and post the solution here in case someone might find it useful

@dharman thank you very much for sharing this! It’s really helped alleviate this part of my workflow!

I’ve been scouring the API docs and cannot seem to figure out how to set the .pdf settings to be black and white. Obviously if my curves are already black this isn’t an issue but when printing things like linked blocks sometimes the layer colors are well… colorful and by default I need all documents to be printed black and white.

I could create a script that sets layer/object colors to black but I want to preserve user’s layer colors if possible

Here’s the bit of code from your Print PDF component where the .pdf is being written:

if P:
    pdf = Rhino.FileIO.FilePdf.Create()
    dpi = 300
    #loop through all layouts and print to single page pdf
    for i, view in enumerate(layouts_get_by_names(LN)):
        #Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.PageHeight
        #Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.PageWidth
        w = mmToInch(view.PageHeight)
        h = mmToInch(view.PageWidth)
        size = System.Drawing.Size(h*dpi, w*dpi)
        settings = Rhino.Display.ViewCaptureSettings(view, size, dpi)
        if M==True:
            settings.RasterMode = True
        pdf.AddPage(settings)
        if not os.path.exists(FP):
            os.mkdir(FP)
    filepath = os.path.join(FP, FN+".pdf")
    print filepath
    pdf.Write(filepath)

If you or anyone else happen to have any leads on setting the .pdf capture to black and white that would be very much appreciated!

Thanks again for sharing!

EDIT:
I think this is what I’m looking for:
https://developer.rhino3d.com/api/rhinocommon/rhino.display.viewcapturesettings.colormode

EDIT2:
It appears that ViewCaptureSettings.ColorMode is read only? Is this the case or am I missing something obvious.

I would like to be able to set the color mode from python like this:

        if M==True:
            settings.RasterMode = True
        settings.ColorMode = CM

Where CM is an input variable of integer type, so by setting the int to 2 I should be setting it to Black And White according to the .ColorMode method.

Thank you!

EDIT 3:
Okay I figured it out, sharing here if it helps anyone:

    # Determine the color mode based on the value of CM
    if CM == 0:
        color_mode = Rhino.Display.ViewCaptureSettings.ColorMode.DisplayColor
    elif CM == 1:
        color_mode = Rhino.Display.ViewCaptureSettings.ColorMode.PrintColor
    elif CM == 2:
        color_mode = Rhino.Display.ViewCaptureSettings.ColorMode.BlackAndWhite
    else:
        # Handle invalid CM values here (optional)
        color_mode = Rhino.Display.ViewCaptureSettings.ColorMode.DisplayColor

Perhaps there’s a more concise/elegant way to handle this?

2 Likes

I’ve just put out a plugin called Drafthorse for managing Layouts, and the code is all shared on github
Covers a lot of the same ground as @dharman 's components listed above, but I am planning to keep developing them. Rhino 8 will have some significant improvements, since layouts and details now have GH types. Please give it a try and let me know if there are any improvements you are interested in seeing.

2 Likes

Yes I just saw this the other day! I’m excited to try. I’ve extensively modified the code in this post to have more functionality as I’ve gotten further into automated document sets.

Still a long ways to go to get it working in all typical situations but it’s getting there.

Looks like your plugin will cover a lot of what I am attempting.

Thanks for sharing, I’ll report back as I get into it

1 Like

Hi all,

i’m trying right now Drafthorse but hit a wall when going above 400 layouts. It simply crash.
Layout is A4, tried it empty (no text, no curve, no hatch, no bloc) doesn’t seem to help.
I observe a huge linear increase in ram when layouts are added, but on a 64G ram PC it crashes around 16G of ram wich correspond to around 400 layouts.

I can always divide everything to stay around 250 layouts per batch, but as i saw that @dharman had pulled 1300 layouts i’m searching from where does the problem come.
Running last Rhino 8 SR6 on windows 11

Try to create a loop which can be linked to timer
like first print take 2 sec after 2 sec the next print like wise so u know how much time gonna take for print outs (every print take 2 sec ) so u dont crash the PC

Yeah i splited the things by column.

The problem seems really related to the make presentation phase, grasshopper create, unfold, annotate the 800+ geometry relatively easily.
Writting down 400 pdf take just a few seconds as well.