C# component dynamic variable output question

unhandled

(Andrew Jinho AHN) #1

I’m trying make a custom component capable of variable output(similar to explode tree(bang) component).

I have looked up similar issue on this forum and have found this thread(Component with variable inputs and outputs) but couldn’t go further due to my limited coding experience.

It would be the best if I was provided with some examples but couldn’t find one. :cry:


#2

I think it is not possible to do this in a scripting component, or if it can be done, it will be an bug nest (try code below).
This functionality is done with compiled components (in Visual Studio) overwriting methods that allow you to handle this.

private void RunScript(int N, ref object D1, ref object D2, ref object D3, ref object D4)
{
  IGH_Param outP = this.Component.Params.Output[0];
  this.Component.Params.Output.Clear();
  this.Component.Params.Output.Add(outP);
  for(int i = 1; i <= N; i++){
    IGH_Param p = new Grasshopper.Kernel.Parameters.Param_GenericObject();
    p.Name = "Output " + i;
    p.NickName = "D" + i;
    this.Component.Params.Output.Add(p);
  }
}