# DataTree<T> class

Namespace: [Grasshopper](https://developer.rhino3d.com/api/gh1/namespace/grasshopper.md) · Assembly: [Grasshopper](https://developer.rhino3d.com/api/gh1/assembly/grasshopper.md)

```cs
public class DataTree<T> : IGH_DataTree
```

Implements basic Grasshopper Data Tree functionality in an easy-to-use class. This class is used primarily in Scripting components. If you're using the Grasshopper SDK you should consider using the [GH_Structure<T>](https://developer.rhino3d.com/api/gh1/type/grasshopper.kernel.data.gh-structure-1.md) class instead.

**Type parameters:**

- `T`: Data type of this class.

## Constructors

- [DataTree<T>](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/ctor.md): (4 overloads) Default constructor, create an empty data tree.

## Properties

- [BranchCount](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/branchcount.md): Gets the number of branches defined in this tree.
- [Branches](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/branches.md): Gets a list of all the data-arrays in this tree
- [DataCount](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/datacount.md): Gets the total number of data items (including nulls) stored in all branches.
- [Paths](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/paths.md): Gets a list of all the branch paths in this tree.
- [TopologyDescription](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/topologydescription.md): Gets a description of the topology of the tree. Useful for debugging purposes.

## Indexers

- [Item](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/item.md): Gets or set the data item at the specified path and index.

## Methods

- [Add](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/add.md): (2 overloads) Add (append) a data item to the specified branch in the tree. If the branch doesn't exist yet, it will be created.
- [AddRange](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/addrange.md): (2 overloads) Add (append) a list of data items to the specified branch in the tree. If the branch doesn't exist yet, it will be created.
- [AllData](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/alldata.md): Collects all data in the tree in a single list. Does not alter the topology of this tree.
- [Branch](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/branch.md): (3 overloads) Gets the list of data which belongs to a given Branch path.
- [Clear](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/clear.md): Clears the entire tree.
- [ClearData](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/cleardata.md): Removes all data from all branches without affecting the tree topology.
- [EnsurePath](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/ensurepath.md): (2 overloads) Create a new branch with the specified path if it doesn't already exists.
- [Flatten](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/flatten.md): Flattens the entire tree into a single path.
- [Graft](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/graft.md): (2 overloads) Graft all paths in this tree. "Grafting" means appending a new branch for every item in an existing branch.
- [Insert](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/insert.md): Insert a data item to the specified branch in the tree. If the branch doesn't exist yet, it will be created.
- [ItemExists](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/itemexists.md): Test if the specified path + item index are defined inside the tree.
- [MergeStructure](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/mergestructure.md): Merge a Grasshopper parameter structure into this DataTree. Expert user function. If you don't know what a GH_Structure(Of T) is you don't have to worry about this method.
- [MergeTree](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/mergetree.md): Merges two trees together. Data inside similar branches will be merged into single lists and unique paths will be appended. The other tree will not be altered, so beware that data is now shared among both trees.
- [MergeWithParameter](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/mergewithparameter.md): Utility function for assigning Script Data Trees to output parameters. Expert user function, don't worry your pretty little head about this one.
- [Path](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/path.md): Gets the data path at the specified index.
- [PathExists](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/pathexists.md): (2 overloads) Test if the specified path is already defined inside the tree.
- [RemovePath](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/removepath.md): (2 overloads) Removes a path and all associated data from the structure. If the path doesn't exist, nothing will happen.
- [RenumberPaths](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/renumberpaths.md): (2 overloads) Renumber all paths in this data tree, using a single incrementing path index.
- [SimplifyPaths](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/simplifypaths.md): Simplify the branches in this tree by removing all identical path entries. The length of the shortest path will be indicative of the similarity search depth. If this tree only contains a single branch, the branch wil be simplified to its last index.
- [ToString](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/tostring.md): Creates a brief description of the tree.
- [TrimExcess](https://developer.rhino3d.com/api/gh1/type/grasshopper.datatree-1/trimexcess.md): Trims the excess allocated memory in all branches
