Grasshopper

algorithmic modeling for Rhino

How to repeat certain items of a list? and how to insert multiple items between repeats?

Hello,

I am having trouble manipulating lists effectively.  I have the following problem: Say I have list: 

1. A

2. B

3. C

4. D

5. E

6. F

7. G

8. H

I would like to make a definition that takes this list, and says "repeat every Nth element", meaning say if N was 3, I would get A B C C D E F F G H.    I would also like to be able to then insert a list of 3 elements in between each of the repeats.  For example, I wanted to insert: 

1. 1

2. 2

3. 3 

into the list, I would get A B C 1 2 3 C D E F 1 2 3 F G H.  

It seems like an easy task, but I cannot for the life of me figure out how to do it, I must be making a very basic mistake. I am new to grasshopper, so any and all help I could get would be GREATLY appreciated!

Views: 3842

Replies to This Discussion

How hard this becomes depends a bit on the amount of manual work you're willing to put into it.

Duplicating every Nth item X times can be done by creating a stacking pattern. I made this one by hand, but you could use some combination of components to control the length of the '1' run and value of the repetition.

Inserting lists into other lists is in fact the much more complex. Grasshopper vanilla only provides a component for inserting individual items into a list (although many items can be inserted at once, making the insertion calculation index maths a lot easier).

To do it right you'll have to repeat the '1', '2', '3' as many times as you need to insert it, and then, generate the matching list of insertion indices '3', '3', '3', '7, '7', '7', ... This will involve a fair amount of Series or Duplicate, or Stack, or whatever...

Attachments:

Wow thank you for the quick response!  Just also wanted to say thanks for creating this program! It should be known that as someone who has a background in visual arts and NOT in programming grasshopper is an incredible and intuitive way for me to learn to think in this way, something I never thought I'd be able to do! 

I will try your suggestions and repost if I am able to get results, or if I have further problems--thanks so much!

Alternate solution that just appends the the correct number of final insertions with Merge instead.
Learned something new today though :) (stack)

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service