Grasshopper Preview on a Layout?

Hi all,

I’m wondering if there is an easy way to get Grasshopper geometry to Preview in a Layout (not in a Detail View, onthe Layout Page itself)? For instance, if I generate some text that I’d like to see Previewed for the user (as part my titleblock for instance) - I can’t seem to figure how I’d get that to show up as a Preview?

import Rhino

# Set up Text Object Parameters
basePlane_Origin = Rhino.Geometry.Point3d(0,0,0)
basePlane_Normal = Rhino.Geometry.Vector3d(0,0,1)
basePlane = Rhino.Geometry.Plane(origin=basePlane_Origin, normal=basePlane_Normal)

# Create the Text Object
txt_ = Rhino.Geometry.TextEntity()
txt_.Plane = basePlane
txt_.Text = _txt

# Create Surfaces from the Text for Previewing
dimStyle = Rhino.DocObjects.DimensionStyle(Name='_temp')
txtAsSrfcs = list(txt_.CreateSurfaces(dimStyle))

I can create and manage the text all fine and GH Preview works in the 3D View of course

But in a Layout view it doesn’t seem to show up? It will show up inside a Detail View of course - but I’m trying to get it to show up on the Layout page itself, not inside a Detail View.

If I ‘Bake’ the text out to the Layout (while in the right Layout view) it will show up just as I want - ultimately that Baked geom is what I’ll use when I print the Layouts…

but in order to set it up correctly the Preview is needed obviously. Any thoughts on what I’m doing wrong here and if there is a better / easier way to do Grasshopper previews on a Layout page but not inside a Detail View - on the Layout itself?

thanks very much for any input!

1 Like

hey, did you figure this out by any chance? i think it would be pretty useful too.

1 Like

It’s not possible I think, we went through quite some trouble making sure the previews are drawn only in 3d viewports.

thanks @DavidRutten
I realised i could just set the text to display somewhere outside what the detail sees, and create a separate detail for the text.
PS: forgive the fanboy gushing but thank you for making grasshopper - its the most amazingly fun and powerful design tool I have used :smiley:

Hi @aditya.d.bhatt, @DavidRutten

Actual in the end I was able to make it work after all - or at least something close enough to a real ‘preview’ for my purposes of organizing layout elements before baking.
The image below is from a table-builder-thing I made to batch PDF-print geometry and params in a table format onto sheets direct from GH:

I had to implement a custom ‘Conduit’ with an on/off control. I basically followed the process shown here: Rhino - Overlay Text Display Conduit

though to be honest its a bit above my pay-grade to fully understand all of whats going on there. But I was able to make it work just fine in the end for my purposes.

The code to do a simple version in a GH Python component looks something like:

import Rhino
import scriptcontext as sc
from System import Object
import System.Drawing

class CustomConduit(Rhino.Display.DisplayConduit):
    def DrawForeground(self, e):
        # Set up Txt Input Params
        color = System.Drawing.Color.Blue
        Text3d_Origin = Rhino.Geometry.Point3d(0,0,0)
        Text3d_Normal = Rhino.Geometry.Vector3d(0,0,1)
        align = Rhino.DocObjects.TextHorizontalAlignment()
        Rhino.DocObjects.TextHorizontalAlignment.value__.SetValue(align, 1) #1=Center

        # Create the new 3D Text Entity
        Text3dEntity = Rhino.Display.Text3d( self.txtToPreview )
        Text3dEntity.TextPlane = Rhino.Geometry.Plane(origin=Text3d_Origin, normal=Text3d_Normal)
        Text3dEntity.Height = 1
        Text3dEntity.HorizontalAlignment = align
        # Display the new 3D Text
        e.Display.Draw3dText(Text3dEntity, color)

def showafterscript(_txtToPreview, _preview):
    newConduit = None
    newConduit = CustomConduit()
    newConduit.txtToPreview = _txtToPreview

    if not _preview:
        if sc.sticky.has_key('myconduit'):
            oldConduit = sc.sticky['myconduit']
            oldConduit.Enabled = False
            newConduit.Enabled = False
        if sc.sticky.has_key('myconduit'):
            oldConduit = sc.sticky['myconduit']
            oldConduit.Enabled = False
            newConduit.Enabled = True
            sc.sticky['myconduit'] = newConduit
            newConduit.Enabled = True
            sc.sticky['myconduit'] = newConduit

    if newConduit.Enabled: print('Conduit Enabled!')
    else: print('Conduit Disabled!')


# Text Preview
if txt: showafterscript(txt, True)
else: showafterscript(None, False)

hope that helps.


hi Ed this is amazing! I have never tried to use python so far. Im curious about your table builder thing because that seems to be referencing layout and file names and compile them into the display. is this something you have published on food4rhino?

Hi Aditya,

Woops- sorry, I thought you were asking about the python code - just assumed. My bad. As David said, there doesn’t seem to be any ‘out of the box’ method for previewing on Layouts I’m afraid. Doing it as custom code seems to be the only method I’m aware of.

Re: the tool there: no I havn’t shared it just yet - its actually a part of a much larger project we’re working on and will hopefully be sharing in the coming months (right now targeting Sept 2020). But yes: its built to enable us to auto-generate a series of PDFs from our GH analysis (we are an architectural energy modeling firm and do a lot of analysis work in GH currently). We want to output lots of drawings (floor plans, etc…) which will automatically include the data inputs for our models, as well as output results - so we’ve been working on this batch-printer as part of our larger custom tool-set. It controls the Rhino side so it changes layer-states, viewports, visible geometry, etc… all from inside the GH tool. So we can set it all up, hit run, and it’ll output dozens of PDFS for us in a predictable, repeatable manner. So far so good. Quite a few kinks still to work out before its sharable though I’m afraid.

I’ll let you know once I have it ready to share if you are interested though.

all the best,

totally interested! I used to daylight simulation and thermal modelling when ecotect was still a thing :smiley:
Im now out of touch with the tools, working in practies where it it isnt really priority. I am now looking at workflow in my current job, and have been tasked with figuring out a way to design, manage information and produce content within rhino- instead of the usual <model in rhino, draw in autocad, diagram in illustrator, and calculate in excel LOL> and to this end am trying to develop a system in rhon+grasshopper+visualarq. So far I have managed to use text fields to reference information into a title block. basic stuff but does a fair bit of what i need for this stage.

Hi -

This got a bit extended in Rhino 7:


sweet! Im sure my practice will be happy to know there is good new around the corner :slight_smile: In the meanwhile we will make do with what Rhino 6 can do since we are also keen on VisualArq.

ofcourse the drawback here is that its almost impossible to match 2 viewports in different perspectives!