How to write "nothing" to a DataTree?

Hi guys,

I have been trying for hours to create an empty DataTree matching an existing, non-empty DataTree. I could not find a component to do that - is there any component, that I missed, or maybe a simple trick on how to easily do that?

In order to solve this, I have created a very little Python script, that does “almost” exactly, what I want. But I got stuck on the last little thing. When I add “None” to the DataTree, it gets a < null > attached, instead of just an empty path.

from Grasshopper import DataTree
import System

tree = DataTree[System.Object]()

for path in x.Paths:
    tree.Add(None, path)

a = tree

datatree.gh (13.7 KB)

I get the desired result using a CleanTree component (as shown on the right), but I want to avoid this extra step and create the empty DataTree directly in GHPython.

Can you please help me on how to do that? It should really be a very minor addition/modification to the script.

Oliver

for path in x.Paths:
	tree.Add('', path)

change None to ‘’, which represents empty string.

Thank you, but that is not what I want. Your solution fills the DataTree with empty strings, but I want is the DataTree is actually empty - like shown on the right in my image.

Add tree.ClearData()

I am curious as to why you would want to do that?

3 Likes

Thanks a lot @Wiley - that’s now exactly what I was looking for. I tried “exactly” this before (well, obviously not really exactly) and it didnt work… but now I did it again it does. :thinking:

The reason I need this empty tree is that I have two trees - one holding geometry and one holding transforms. By merging the transforms with the empty tree I can make sure the adressing is not mixed up by automatic branch “matching”. Now every transform goes to the correct geometry - although I am feeding all geometry and all transforms through only one transform geometry component.

Thanks again and have a good day.

1 Like

if you want to keep it even simpler:

from Grasshopper import DataTree
import System

tree = DataTree[System.Object](x)
tree.ClearData()
a = tree

the DataTree class has a constructor that copies another DataTree.

1 Like
tree = DataTree[System.Object](x)
tree.ClearData()

Yes - something like this is what I assumed should be possible right in the beginning - but had no idea on how to do it. Very elegant solution!

Hi, was looking for this same topic but I want to find a way without c# or python. So here is it…

Thanks @Flux - that’s really a nice solution.

Here for future readers a more detailed screenshot and the script to quickly check it.

empty_tree.gh (12.4 KB)