C# Params trying to list all output parameter nicknames

I’m trying my hand at a custom C# component to list all of the output parameters in my grasshopper document.

I’ve completed Long Nguyen’s excellent online workshop but I’m stumbling at accessing the ‘.Params’ correctly in my code.

            objectOutputNickNames = new List<string>();
            foreach (var ghObject in thisGHDocument.Objects)
            {
                if (ghObject != null)
                {
                    foreach(IGH_Param outputParameter in ghObject.Params.Output)
                    {
                        objectOutputNickNames.Add(outputParameter.NickName);
                    }
                }
            }

I’m getting the error “‘IGH_DocumnentObject’ does not contain a definition for ‘Params’”

I’ve been able to successfully query the grasshopper document for a list of object nicknames, but I’m stumped on getting a list of output parameter nicknames.

I’m sure there is a simple solution to this, but all of my searching for example code uses ‘Params’ which I don’t know how to access.

Any suggestions would be greatly appreciated.
Leo

IGH_DocumentObject is the basic interface for all objects, a Scribble or a Group are also IGH_DocumentObject, but they dont have any parameter.

Only IGH_Component has the property Params, where from there you can access the output parameters. On the other hand, there are also objects that are pure parameters IGH_Param, like the slider or the button, and since these are data providers, they have output.

Then, as you go through the objects, you have to cast the components and then access their outputs, and on the other hand cast the parameters.

objectOutputNickNames = new List<string>();
foreach (var ghObject in thisGHDocument.Objects) {
  if (ghObject != null) {
    if( ghObject  is IGH_Component comp) {
      foreach(IGH_Param outputParameter in comp.Params.Output)  {
        objectOutputNickNames.Add(outputParameter.NickName);
      }
    }else if( ghObject  is IGH_Param param) { //In case that you need it
       objectOutputNickNames.Add(param.NickName);
    }
  }
}
2 Likes

Aha thanks so much Dani_Abalde!

That clarifies a lot for me and eliminates the error I was getting.

:smiley: