Grasshopper

algorithmic modeling for Rhino

how to convert two-dimensional array to tree in ghpython?

as the pictrue:

                   how to convert two-dimensional array to tree in ghpython?I wanna output of 'list' as same as the 's'.

Thank you

-Carcassi

Views: 2328

Replies to This Discussion

Hi,

This is an exercise I am always showing when I teach GH-oriented Python  to my students. It grafts a list of data into a tree, not through the graft method, but using a for loop instead. By changing the loop you will get the desired result.

 

import Rhino
#import grasshopper classes
import clr
clr.AddReference("Grasshopper")
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree

newlist = []
newlist = x[:]
print newlist

graftedTree = DataTree[object]()
for i in range(len(newlist)):
str =newlist[i]
path = GH_Path(i)
graftedTree.AddRange([str],path)

A = graftedTree

Best,

M.

Attachments:

would you mind explain the clr module? I dont know what it is

Thanks

-Carcassi.

By importing clr you can basically reference any compiled code in your disk. In this case we are importing the grasshopper.dll. This means we can access pretty much all the classes and methods of the gh plug-in.

This import is automatically available in the VB and C# components, but in the case of the Python one which is a third party component (cc Giulio Piaccentino) this import is not predefined.

Best,

M.

Thanks

-Carcassi.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service