Grasshopper

algorithmic modeling for Rhino

Hi,

I am developing a plugin where I make use of custom parameters. Since I would like to keep my own parameters independent of the Rhino/ Grasshopper libraries, I made use of tuples to store my own class along with the rhino representation, like:

public class GH_InterfaceData : GH_Goo<Tuple<Interface,Brep>>, IGH_PreviewData
{

    public BoundingBox ClippingBox { get { return new BoundingBox(); } }

    public void DrawViewportMeshes(GH_PreviewMeshArgs args)
    {
        System.Drawing.Color col = System.Drawing.Color.Orange;
        args.Pipeline.DrawBrepShaded(Value.Item2, new
        DisplayMaterial(col,0.5));

    }
    public void DrawViewportWires(GH_PreviewWireArgs args)
    {

    }

}

Now this data is represented as a custom parameter in the input and output of components by another class that inherits from GH_Param. So that I can register them in the GH_OutputParamManager and GH_InputParamManager.

In this particular example I would like to display a Brep. However I want it to react like any standard grasshopper component would, when it outputs brep geometry, so:

  1. The geometry in the Rhino viewport is red like any other grasshopper displayed geometry when the component is not selected and has the same transparency. Is this color/ transparency defined somewhere in Grasshopper or is it a static System.Drawing.Color color? (If so which one?)
  2. The geometry turns green when the component is selected.
  3. If you want the geometry to display when the component preview is turned on, do you need to register a GenericParameter in the GH_OutputParamManager or is there a way to have the custom parameter do this by default?
    The reason I would like to avoid the GenericParameter is because I want to be in control of which parameters can be passed to which of my components.

Thanks!

Dion

Views: 2591

Replies to This Discussion

Hi Dion,

the args parameter provided in DrawPreviewMeshes contains the display material you should use to draw your meshes.

If you want to draw things from your IGH_Param, then implement IGH_PreviewObject.

--

David Rutten

david@mcneel.com

Tirol, Austria

Hi David - I can see how to get the correct colour from IGH_PreviewArgs, however I can't seem to find a flag that states whether the component is selected so I can toggle my colours appropriately - could you point me to where that information is hiding please?

Is this code in an IGH_PreviewAwareData or IGH_PreviewAwareObject?

If it's in data, then you should already be given the correct preview data for the selected state of the containing object. If it's in object, then you need to look at your attributes to see if you're selected. You may have to look at the attributes of the top-level object, there's no guarantee that input/output parameter attributes get selected when the component gets selected.

It's a component that inherits from GH_Component. I am creating my preview using DrawViewportWires (maybe this is not the best way to achieve what I am trying to do). The output I am trying to display in the conventional Grasshopper way is a DataTree of curves that are the only output of the component.

Ok, when you're in GH_Component and you're overriding DrawViewportWires, then you can just look at the attributes:

if (Attributes.Selected)

  ...selected colours here

else

  ...unselected colours here.

That worked, thanks!

Hi Hugh

I am also trying to do a similar thing where text is either green or red depending on whether the component is selected or not. What I cant work out is how to actually obtain Attributes.Selected... Would you be able to share your code so I am work this out? Im new to visual studio and C#

You should be doing this under DrawViewportWires or DrawViewportMesh. You can use Grasshopper.Kernel.GH_DocumentObject.Attributes, then just switch on it when it's true.

So my example code for this part simply looks like:

System.Drawing.Color boundaryColour = args.WireColour;
if (Attributes.Selected == true)
    boundaryColour = args.WireColour_Selected;

Hi David. I have a similar problem but I would like to override the default preview colors for a custom data type GH_GeometricGoo that implements the IGH_PreviewData interface. Where would one typically do that ? I couldn't find the IGH_PreviewAwareData in the SDK. 

Thanks. 

Andrei. 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service