Grasshopper

algorithmic modeling for Rhino

Hi everyone, I'm just getting into understanding how branches and datatrees work in Python. Simple example attached: I have branches each containing a series of numbers, and I want Python to find the smallest number within each branch. Using the 'min' command only returns the smallest in the last branch for some reason. If anyone could lend me a quick hand I would really appreciate it. Thanks!

Views: 795

Attachments:

Replies to This Discussion

I figured it out using:

for i in range(x.BranchCount):
ptList = y.Branch(i)
print min(ptList)

Hi Andrew

You don't need tree access. If you use list access, then min(ptList) will be enough.

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Btw, do not print. This creates text. Use an output variable name.

Thanks for the reply Giuliu. Yes the tree access was beginning to give me other issues. But I'd just like to clarify, if I use list access and min(ptList), would would the correct syntax be? I tried several variations and always received errors. 

This way works (if I understand what you are after)

Attachments:

Indeed it does. Sometimes it's the simplest things... Much appreciated. 

I'm having a problem which is really puzzling me. When I try to further iterate on these sub-lists in the Python script, it keeps operating ONLY on the final list, ignoring all others. The output A displays all results correctly, but within the script it does not. Any further work on these lists in Python can't be performed.

The script to the left shows what I want, which is a result which accessed all four sub-lists.

Any help as to what I'm doing wrong would be greatly appreciated. At this point I can't perform any further work on my sub-lists. Thanks!

Attachments:

Okay, so I have figured out one puzzle just to introduce another. With:

for branchCount, branch in enumerate()

and the input set to Tree Access I've been able to get a bit further. But This has brought other strange problems. I'm just attaching the overall script I'm trying to work with. I want to perform operations on any of the 8 geometry branches that contain a curve smaller than, say, 30. I've successfully exploded each curve as can be seen in the script. But further operations, again, only operate on one value. Further, the outputs just repeat every value in every list for each branch. I'm quite lost with this. 

Thanks for any suggestions. 

Attachments:

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