Defining DataTree

Hello everyone. This is my first time trying to assign a data tree as an input in the GH template for visual studio and I get this error. Can someone kindly help me how to solve this problem?

Best,
Mahan

The intellisense is pointing you to the correct Syntax.

DA.GetDataTree(0, out curvesTree);

I assume curvesTree is DataTree of Curve data type, so then replace with

DA.GetDataTree(0, out GH_Structure<Curve> curvesTree);
1 Like

Hello, Su. I already had tried it but then I got another error that I can not convert a DataTree to GH_Structure .

DataTree<T> are only supposed to be used inside Scripting components. Once you’re writing actual components switch to GH_Structure<T>, it’s what Grasshopper itself uses.

1 Like

As @DavidRutten said, if you are writing actual Component use the Grasshopper wrapper data structure.
So instead of declaring

DataTree<Curve> curvesTree = new DataTree<Curve>();

Use this

GH_Structure<Curve> curvesTree = new GH_Structure<Curve>();

Sadly that’s not possible. GH_Structure has a type constraint on what T is allowed to be. It must always be a type which implements the IGH_Goo interface. This is also the primary reason why DataTree was added, it removes that constraint.

@DavidRutten, oh yes you’re right. My bad!
It will be :

GH_Structure<GH_Curve> 
1 Like

@DavidRutten @shaique.uddin thanks for your help. The next issue is that I can not get the same method for " GH_Curve" class as what I used to get from " Curve" in this way. For instance I want to convert all the data in the GH_Structure<GH_Curve> to NurbsCurve and there is no method for that.

Best,

Mahan

GH_Curve is not a replacement for curve, it is a wrapper for all Rhino curve types allowing grasshopper to deal with the data. Most of these wrapper classes (GH_Boolean, GH_Integer, GH_Curve, GH_Brep, …) have a Value property which allows you to access the underlying data.

2 Likes

Thank you David for your clarification.

Best,

Mahan