Grasshopper

algorithmic modeling for Rhino

Hello!

I am working on a simple code for a kangaroo construction, so i need to recreate the lines i made as polylines that are created between the start point the section points and then the end point of the lines (to work as node - spring - node - spring etc.)

First of all, in the grasshopper code i create the lines (that i need to recreate as polylines) and solve their intersection events. Grasshopper returns them in a point list, that has a collection of points. The list of points is one - dimensioned meaning that only has the list of points as they were created from the programm.

In the python script i am rearranging this list in order to get a Tree with branches of lists of points.(for every line a series of points arranged according to the code).

The problem that i have right now is that the output of the python script is having syntax problems and returning the tree as an IronPython.Runtime.List and not as a tree of branches made from a points list.

The script is the following

import rhinoscriptsyntax as rs

k = 0

NL = [[0 for x in range(n-1)] for y in range(n)]

for i in range(n):
for j in range(n-1-i):
NL [i][j+i] = PL[k]
NL [i+j+1][i] = PL[k]
k = k+1


print(NL)

Views: 484

Attachments:

Replies to This Discussion

Hi,

This is not the way DataTrees work, nor they are handled automatically in python.

Try the following in an editor to get your head around.

from Grasshopper import DataTree
from Grasshopper.Kernel.Data import GH_Path
import Rhino as rc

#construct a list
list01= [0,2,34,4]
list02=["alpha", "beta", "gamma", "delta"]
list03=[rc.Geometry.Point3d(0,0,0)]
my_list = [list01,list02,list03]


#and transfer it to a tree
my_tree = DataTree[object]()

for i in range(len(my_list)):
my_path =GH_Path(0,i)
my_tree.AddRange(my_list[i],my_path)

Best,

M

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service