How to stop specific outputs of a Grasshopper component from displaying results automatically
In this previous post, a way to stop a component from automatically displaying results on calculation was shown. This put the onus of previewing results directly onto the user. However, there may be a time when you wish for the user to view some results, but not all of them.
For example, maybe you have a component which has a primary function to colour the mesh and output that mesh result to Rhino. However, a secondary function of the component is to provide the points which make up the mesh (the mesh vertices) for debugging purposes (or whatever purpose really, that’s up to you). If you have the component previewing the outputs, you’ll end up with a mesh which is barely visible due to all the points drawn on top of it with red crossed denoting a GH point, similar to the one below. You can only see a mass of red, and it’s only when you zoom in that the green of the mesh is visible.
If you have the component not previewing the outputs (i.e. if you use the method from the previous post), then no output will be visible to the user and they’ll have to either turn on the preview (which could result in the situation above), or get a mesh component and drag the wire from the mesh output to the mesh component to view the mesh. In terms of usability, this isn’t an ideal solution, as it’s placing onus on the user to perform an additional step which, to the average user, would not be overly intuitive, and they may think your component is broken as a result.
Turning preview off for individual outputs
So what’s our solution? Well, just as we can turn the preview off for the whole component, we can turn the preview off for individual outputs. Thus, we can display our mesh automatically to the user with the colours, but the mesh points can be hidden and only viewed by deliberate action from the user (for the debugging purposes (or other)).
To do this, we simply cast the registered output to be of the type IGH_PreviewObject and set the hidden property to true (as done here for the whole component). See the example below for an implementation of this.
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { pManager.AddMeshParameter("Mesh", "Mesh", "Output mesh", GH_ParamAccess.list); pManager.AddPointParameter("Mesh Points", "Mesh Points", "The points that make up the mesh", GH_ParamAccess.list); ((IGH_PreviewObject)pManager[1]).Hidden = true; //Hide the mesh points from the user unless the user wants them }
If you want to hide multiple outputs, you could wrap this into a for loop (see below) to save you having to duplicate lines of code.
for(int x = 1; x < pManager.ParamCount; x++) ((IGH_PreviewObject)pManager[x]).Hidden = true;
Turning the output off, gives us the ability to see our mesh normally (see below), without having to perform extra steps. In terms of usability, this is the favoured format, minimal effort is needed by the user but, for the more experienced users, extra functionality is provided should they need or want it.
Hopefully this helps you create components which only gives the necessary outputs by default and provides optional outputs to the users for additional functionality without immediately detracting from the original default output.