# How to output flattened data?

**URL:** <https://discourse.mcneel.com/t/how-to-output-flattened-data/189231>\
**Category:** Grasshopper Developer\
**Tags:** windows, csharp, rhino8\
**Created:** [August 8, 2024, 5:41am UTC](https://discourse.mcneel.com/t/how-to-output-flattened-data/189231 "2024-08-08T05:41:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yasuda](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/yasuda/32/522402_2.png) [@yasuda](https://discourse.mcneel.com/u/yasuda)\
**Post date:** [August 8, 2024, 5:41am UTC](https://discourse.mcneel.com/t/how-to-output-flattened-data/189231/1 "2024-08-08T05:41:26Z")

</div>

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)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/b/0/2/b0250801892ce7f59915c53ab27b5007fe624c13.png)

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](https://discourse.mcneel.com/uploads/short-url/c3pxZPAEr2TekNEDzIQZXnDYmuJ.cs) (2.4 KB)  
[ListOutput02Component.cs](https://discourse.mcneel.com/uploads/short-url/by36c4rNPo6q09NedTvs9OHrXWr.cs) (2.4 KB)

---

<div class="post-metadata">

**Author:** ![TuomasLehtonen](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tuomaslehtonen/32/438910_2.png) [@TuomasLehtonen](https://discourse.mcneel.com/u/TuomasLehtonen)\
**Post date:** [August 8, 2024, 6:10am UTC](https://discourse.mcneel.com/t/how-to-output-flattened-data/189231/2 "2024-08-08T06:10:34Z")

</div>

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.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/f/4/2/f427695da82222c6ed9848568a7c76a783f4c556.png)

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.

---

<div class="post-metadata">

**Author:** ![yasuda](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/yasuda/32/522402_2.png) [@yasuda](https://discourse.mcneel.com/u/yasuda)\
**Post date:** [August 9, 2024, 12:21am UTC](https://discourse.mcneel.com/t/how-to-output-flattened-data/189231/3 "2024-08-09T00:21:08Z")

</div>

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.

```auto
/// <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);
}

```
