Flatten a tree

Hi all,
i tried to flatten a tree but i donts know how to tell the path…i thought {0}
but that seems wrong

import Grasshopper as Gr
print R


Help is welcome

Well it’s all in the error message:
You have to construct a Gh_path and pass that to flatten, not just an int that looks like a path

The { 0 } is a set

Yea i know because the error information tell me this …but i dont know what this hint mean…i am just a python noob and if i see set its for me like this.
set() …i guess you guys are far more experienced than me.
but thanks for your information

hey @flokart i think i could have worded that better, I’m sorry.

The error message means that the flatten function( or method) expects a very specific type of object, a GH_Path. The link i provided you explains what a GH_Path is, how it can be constructed, and additional info about its methods and properties. I fully understand that the documentation will be very hard to read if someone is starting out with programming, for me it helped a lot to learn about object oriented programming (OOP) to better understand why and how all this different objects in rhino work.

Here is a working code sample:

If you have more questions or problems feel free to ask

1 Like

Thanks a lot lando


I tried this approach but keep getting an error. I`ll attach the image here.

Hey @pmora1990,
I think your input parameter on “x” is not set to tree access?
If you don’t know how to set that up this is a good resource:

1 Like

Thanks, that was the problem