Developing for Grasshopper in C#: Find the class for any Grasshopper component

Grasshopper components showing how the C# component can be used to access the namespace of component classes

When developing for Grasshopper, it is useful to be able to interact programatically with existing components.

The current SDK has patchy documentation and finding where and how to interact with different components can be challenging.

The script below can be used to find the namespace and class for any component. Use a default C# component. Set the first input (x) as a list, and connect your components to this.

    Grasshopper.Kernel.IGH_Param selNumsInput = Component.Params.Input[0];
    IList<Grasshopper.Kernel.IGH_Param> sources = selNumsInput.Sources;
    bool isAnythingConnected = sources.Any();
    var rtnlist = new List<object>();

      foreach (var source in sources)
        IGH_DocumentObject component = source.Attributes.GetTopLevel.DocObject;
    A = rtnlist;

Once you have these namespaces, you can then dig into these components and access a wide range of properties. It’s quite fun to see what you can do with them.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.