Grasshopper

algorithmic modeling for Rhino

How to split a list based on the nr. of item in every branch?

Hi,

Can anyone tel me, how to split a list based on the nr. of item in each branch?


I would like to separate this list in 2 lists based on the nr. of items in each branch so one list contains only the branches with 3 items and one list with the branches with 2 items...

Thanks
//A

Views: 3061

Replies to This Discussion

Feed the data into a "list length" component, test for equality (list length = 2) and then use "dispatch" to separate the data into two sets of branches. If having the resulting data contain branches with 0 items bothers you, you can use "clean tree" to remove those empty branches.
Thanks, do you have any idea if it's possible to solve it in the Path Mapper?

Best
//A
I don't think it is... unless there's some secret way to get the length of a list in a path mapper that I don't know about.
...well, we have the "item_count" in the Path Mapper but I'm not sure how to use it properly! I remember David mentioning a syntax for the Path Mapper, but I can't find that post...

Best
//A
Ah, I had no idea!

Here's the trick:

use path mapper to map from whatever it is to start i.e. {0;0;A} to {(If(item_count=2,0,1))}

Because an equality expression evaluates to true or false which convert automatically to zero or one, you can even simplify it to map to {item_count=2} and leave it at that. But by nesting the if solution as above, it would be possible to separate lists of 3 or more different lengths.
ahh... didn't know about the "if"!

Thanks
//A
Wait, "If" statements work with pathmapper now?

I know they just became available in expressions...
they do indeed! I think everything that's valid in an expression is valid in a path mapper.
Good to know... Now I just need to remember.
Wouldn't it be more flexible to use the list length and dispatch? Path mapper always seem so rigid to me. Most changes in the up stream definition will invalidate your expressions.

Still, I'd like to see some documentation on available path mapper and expression syntax. Did you find that post by David?
the post in question (I believe) is here: http://www.grasshopper3d.com/forum/topics/subdivide-down-paths-with...

but believe it or not, the documentation is right in grasshopper; just double click the path mapper icon in the toolbar and a help doc comes up with a detailed explanation including the special placeholders item_count, path_count, and path_index. (in a little tiny note at the bottom)

quote:

There are additional placeholders available for target masks which allow you to track your overall progress in the data tree iteration.
The "path_index" placeholder is an integer which is incremented for every new data tree branch that gets loaded. For example the "{path_index}" target mask would simplify all branches in the entire tree, while keeping all branches separate.
The "path_count" placeholder represents the total number of branches in the current tree.
The "item_count" placeholder represents the total number of items in the current branch.
Thanks! I always forget to look there. A bad habit I got when those help tabs were not as helpful as they are today.

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