Assign user data to grasshopper component

Hi guys,
Is it possible to assign user data to a grasshopper component (GH_DocumentObject) ?Just like there is UserDictionary property for a RhinoObject , is there any equivalent for a GH_DocumentObject? Is there anyway we could assign something like a Key-Value pair to it?

Hi @Darryl_Menezes what exactly are you looking to do?

Hi @elevelle ,
I want to mark certain components with certain values. For example if I have 5 Number Sliders in a grasshopper file, I want to assign some user text to 2 of them (instead of assigning them names). So when I loop through the GH_Document.Objects, and find these 2 sliders and ignore the other 3.

        GH_DocumentIO io = new GH_DocumentIO();

        GH_Document document = io.Document;

        foreach (var obj in document.Objects)
            if (obj is GH_NumberSlider slider)
                  //If this slider has the special key-value pair, then this is different from all other sliders in the file

Alternative would be to create a custom slider by inheriting the GH_NumberSlider, but Iā€™m trying to avoid this.

Things I can think of:

  • Serializing a dictionary to JSON (or alternative) and storing it in the Description property of the number slider.
  • In a plugin, creating a static Dictionary<Guid,Dictionary<string,string>>, and storing the dictionaries for each slider by the object Guid.

In each case adding and removing key value pairs will most likely be awkward, or require a little coding to create a mini UI

1 Like