How to output flattened data?

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)

The output process for these two components is exactly the same, the difference is the presence of Input.

I want to output flattened data, how should I handle this?
ListOutput01Component.cs (2.4 KB)
ListOutput02Component.cs (2.4 KB)

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.

One way to have more control over it is to output as DataTree or GH_Structure where you have much more options to modify the output path structure.

I’m sure someone has a more profound explanation for this, but this is my take on the subject.

1 Like

Thank you for the very clear explanation.

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);
}