Flatten a tree

python
#1

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
R.Flatten({0})   

Capture

Help is welcome

0 Likes

(Lando Schumpich) #2

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

0 Likes

(jesterKing) #3

The { 0 } is a set

0 Likes

#4

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

0 Likes

(Lando Schumpich) #5

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

#6

Thanks a lot lando

0 Likes

(Pmora1990) #7

Hi,

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

0 Likes

(Lando Schumpich) #8

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

(Pmora1990) #9

Thanks, that was the problem

0 Likes