From List to DataTree with Tree Access

Hi Guys

I am struggling with a List of Point3d objects inside a C# Component.

private void RunScript(DataTree<Point3d> x, ref object A)
  {

    DataTree <Point3d> test = new DataTree<Point3d>();
    Point3d testing = new Point3d(0, 0, 0);
    test.Add(x, new GH_Path(0));
    A = test;
  }

The Input is a list of Point3d objects and I am trying to convert or store it into a DataTree but I get an error “Error (CS1503): Argument 1: cannot convert from ‘Grasshopper.DataTree<Rhino.Geometry.Point3d>’ to 'Rhino.Geometry.Point3d”
How can I access the list and store it?
Thank you!

Hi,

Assuming your x input is a DataTree<Point3d> only containing one branch, you can access the list with x.Branches[0].

This would be a List<Point3d>.
You then need to use test.AddRange instead of .Add to add a list in a new path.

1 Like