Retrieve information about the input and output parameter access types

Hi everyone,
I am looking for a way to get information for the access types of the input and output parameters for multiple components. I am using the following script to get the GUID of the component, and together with that, I need for each one of the input and output parameters their type, name and their access type.

foreach (var objectProxy in Grasshopper.Instances.ComponentServer.ObjectProxies)
 {
        Print( "Guid: " + objectProxy.Guid);
 }

private void RunScript(ref object Guids, ref object Names, ref object Inputs, ref object InAccess, ref object Outputs, ref object OutAccess)
{
  var ids = new List<Guid>();
  var names = new List<string>();
  var inputs = new DataTree<string>();
  var inAccess = new DataTree<GH_ParamAccess>();
  var outputs = new DataTree<string>();
  var outAccess = new DataTree<GH_ParamAccess>();
  var objectProxies = Grasshopper.Instances.ComponentServer.ObjectProxies;
  for(var i = 0; i < objectProxies.Count; i++)
  {
    var proxy = objectProxies[i];
    ids.Add(proxy.Guid);
    names.Add(proxy.Desc.Name);
    var obj = proxy.CreateInstance();
    if (!(obj is GH_Component)) continue;
    var comp = (GH_Component) obj;
    foreach(var input in comp.Params.Input)
    {
      inputs.Add(input.Name, new GH_Path(i));
      inAccess.Add(input.Access, new GH_Path(i));
    }
    foreach(var output in comp.Params.Output)
    {
      outputs.Add(output.Name, new GH_Path(i));
      outAccess.Add(output.Access, new GH_Path(i));
    }
  }
  Guids = ids;
  Names = names;
  Inputs = inputs;
  Outputs = outputs;
  InAccess = inAccess;
  OutAccess = outAccess;
}

Information.gh (8.2 KB)

1 Like

@Mahdiyar Thanks! That works perfectly!

Is there also a method to retrieve the tab (the group of components) name that a component belongs to?
There should exist something like this:
proxy.Desc.TabName

var cat = proxy.Desc.Category;
var subCat = proxy.Desc.SubCategory;

Hi Mahdiyar,

What if I wanna get the information of on specific C# component only, rether than evey component I have. Like I had some codes in the C# component, i wanna get the input and output. I tried to change the line “var objectProxies = Grasshopper.Instances.ComponentServer.ObjectProxies;” but haven’t find a good way.

Hope this help:
Information

private void RunScript(ref object A)
{
  var dt = new DataTree<string>();
  var ids = GrasshopperDocument.Objects.Select(docObject => docObject.InstanceGuid).ToList();
  foreach (var obj in GrasshopperDocument.Objects)
  {
    if (!obj.Attributes.Selected) continue;
    for (var i = 0; i < ids.Count; i++)
    {
      var id = ids[i];
      var pth = new GH_Path(i);
      if (id != obj.InstanceGuid) continue;
      dt.Add(obj.NickName + " (" + obj.Name + ")", pth);
      dt.Add("Category: " + obj.Category + " > " + obj.SubCategory, pth);
      dt.Add("Component GUID: " + obj.ComponentGuid, pth);
      dt.Add("Description: " + obj.Description, pth);
      dt.Add("Draw order: " + i, pth);
      dt.Add("Exposure: " + obj.Exposure, pth);
      dt.Add("Instance description: " + obj.InstanceDescription, pth);
      dt.Add("Instance GUID: " + obj.InstanceGuid, pth);
      dt.Add("Attributes: " + obj.Attributes, pth);
      dt.Add("Namespace: " + obj.Attributes.DocObject, pth);
      var comp = obj as IGH_Component;
      if (comp == null) continue;
      dt.Add("Number of inputs: " + comp.Params.Input.Count, pth);
      foreach (var inputParam in comp.Params.Input)
        dt.Add("    " + inputParam.Name + ", " + inputParam.Access + ", " + inputParam.TypeName, pth);
      dt.Add("Number of outputs: " + comp.Params.Output.Count, pth);
      foreach (var outputParam in comp.Params.Output)
        dt.Add("    " + outputParam.Name + ", " + outputParam.Access + ", " + outputParam.TypeName, pth);
    }
  }
  A = dt;
}

Information.gh (3.4 KB)

2 Likes

Awsome ! Could you tell me where can I find the “GrasshopperDocument” namespace/Method ? Seems that it is not in the RhinoCommon API Site. I want to dive into your code and learn how it actually works.

https://developer.rhino3d.com/api/grasshopper/html/T_Grasshopper_Kernel_GH_Document.htm

1 Like

Got it, THANKS !

Howerver… the input access is perfect, but it seems that all the tree output will be recognized as item access, I don’t why… :face_with_thermometer:

Also, the data type is generic data rether than any specific type (Curve, Line, etc.) This works on general components, but not good for C# components…

Any suggestions? :slight_smile:

See if you can discover the c# componenet Type Hint