Grasshopper

algorithmic modeling for Rhino

Python Basics. Lists in GH to Python? and advice on a recursive function?

Hi,
this is my first post. I've reached the point of grasshopper knowledge where I need to build a recursive function and decided to go with Python as my language.

I understand the basic principals of recursive functions, but I get stuck on the basics of python in grasshopper.

First, how do I manage a GH list input as a list in Python?

I would believe x[0] would retrive the first item in the list, not the first position/letter of the last item in the GH list..

Studied atlv.org, code.algorithmicdesign.net, designalyze.com without success. 

(Copy&paste-GH-functions, HoopSnake nor Loop won't solve my recursive problem)

Last... My end goal is in the form below:

α0x = ξ0

(lji-1i + ξi-1= ξi

Where α is a GH list of floats (Galapagos intervalls of 0.00-1.00),

the size α of will govern my end condition.

x is one value, integer.

lis a GH tree with 4 levels {0,0,0,0} but only one value in the perimeter branch.

To the more experianced out there, do you foresee obstacles with the above? Any inital tip? or a complete solution? ;)

Views: 17696

Replies to This Discussion

Found in debugging an error.. Corrected version:

from Grasshopper import DataTree

pylist = [list(i) for i in alpha.Branches]
outputList = []

for j in range(pylist.Count):
for k in range(len(pylist[j])):
if k == 0:
p = pylist[j][k]*X
outputList.append(p)
if k != 0:
p = (lj[j]-outputList[len(outputList)-1])*pylist[j][k]+outputList[len(outputList)-1]
outputList.append(p)

a = outputList
print a

The file is missing :(

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