Legend2d Viewport Filter

Would love to be able to filter what viewport the 2d legend displays in (similar to the custom preview viewport filter)…

is this possible with the current legend2d parameters? If not would like to request this feature


Hi @jakechevrier, this is a question for @chris! I have almost never used the filters myself but I’m copying it here as a reference.


Sorry for the late response, @jakechevrier ,

Anything is possible but this one is thankfully very easy because of what is exposed in Grasshopper SDK. I don’t really want to change the default behavior of the the Preview Visualization Set component without knowing why exactly you want to change the preview of only the legend and nothing else. But you can get the component to filter any geometry in whatever viewport you want by tweaking the code a little.

You can see that these are the lines of code within component that are drawing the 2D legend in the Rhino scene:

The display variable there is a DisplayConduit object that Grasshopper uses in all components to render stuff out to the Rhino scene. You can see that Grasshopper passes this conduit to us by calling a DrawViewportWires method that we have overwritten in the component, which all Grasshopper components have if they render stuff out to the Rhino scene. And we get the DisplayConduit from the DrawEventArgs that Grasshopper passes in:

Following the links to RhinoCommon SDK above, you’ll see that DrawEventArgs also has a Viewport property.

So, if you want to override Grasshopper’s default behavior of rendering things to all viewports for this component, you just need to add a line of code like the following, which inserts a check for the name of the viewport before drawing of legend 2D text and the sprite within it:

viewport = args.Viewport
if viewport.Name == 'Perspective':
    for draw_args in self.vis_con.draw_2d_text:
    for draw_args in self.vis_con.draw_sprite:

That will get the legend to render in only Perspective mode and not any other.

Here is the sample file if you want to see for yourself.
customize_vis_set_preview.gh (40.4 KB)

Hope that helps.


yet again, you are amazing! thank you so much for this write up really appreciate it!

1 Like

I’m just making a note here that we made an official change to the component and it’s documented on this other thread: