I’m writing a custom Grasshopper component in C# which is overriding DrawViewportWires(). In the component I use DrawBrepShaded() and DrawCurve() to set custom display colours, based on what the user have specified, and it works fine. .
The problem is that I would like to revert to using the default GH display settings (green when selected, otherwise red) whenever nothing is specified and I’m stuck on how to do that. I know I can access the default colors by args.ShadeMaterial, args.ShadeMaterial_Selected, but then I also have to add checks for if the component is selected/not selected/hidden.
Is there any smoother way to resort to default display settings that I’m missing here? Or do I simply just have to do the checks and then assign green/red/nothing as any other material?
If the Brep you want to display is included in the output parameters (meaning it would be displayed by the base implementation of DrawViewportMeshes), you can just call the base implementation of DrawViewportWires.
public override void DrawViewportWires(IGH_PreviewArgs args)
{
if (materialDefined)
DrawToViewportWithCustomMaterial();
else
base.DrawViewportWires(args);
}
Also IMHO you should probably be overriding DrawViewportMeshes(), not DrawViewportWires(), if you are rendering “shaded” representations of geometries.
Anyway, checking for component’s disabled and selected status is fairly easy.
I’m just writing this without testing it, but something like this should cover your case completely.
private Brep Geometry;
private Color? Color;
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
if (Locked)
return; // exit early if component is disabled
else if (Geometry is not null && Color is not null)
args.Display.DrawBrepShaded(Geometry, new Rhino.Display.DisplayMaterial(Color.Value));
else if (Geometry is not null)
args.Display.DrawBrepShaded(Geometry, new Rhino.Display.DisplayMaterial(Attributes.Selected ? args.ShadeMaterial_Selected : args.ShadeMaterial));
}