I am creating a custom component in C#.
This component is simply a component that outputs list data.
However, when I added a new Input, it outputs structured data. (see image)
I think the behaviour stems from how Grasshopper handles the input items in regards to how the output paths are handled. So if you pass the input as a List, the output path differs from passing in an Item. The automatic “one-to-many” behaviour kicks in, I think.
This can be tested also with script components by changing the input “type” between Items and Lists.
I think I did not understand the behavior of grasshopper correctly.
I changed the output to DataTree from your hint and got the output as I intended.
Many thanks for your help.
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddTextParameter("Text", "T", "Text to output", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Guid", "G", "Guid data", GH_ParamAccess.tree);
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
string text = "";
if (!DA.GetData(0, ref text)) return;
DataTree<Guid> outputTree = new DataTree<Guid>();
GH_Path path = new GH_Path(0); // Create flattened list with single path
for (int i = 0; i < 10; i++)
{
outputTree.Add(Guid.NewGuid(), path);
}
DA.SetDataTree(0, outputTree);
}