Grasshopper

algorithmic modeling for Rhino

Hello friends, first question here:

I've got a linear array of boxes, and I have used a function (with the help of a thread on here) that tells me if the total number of objects in the array is odd (outputs a boolean true or false). Now I would like to, if this boolean is "true", cull the last item of the array.

Any suggestions?

Views: 4376

Replies to This Discussion

Hi,

you can try this solution:

Or you use "Cull Index" component from Sets/Sequence

Hope this helps,

Raul

Attachments:

Would you happen to know how to add a conditional statement to that, so that it only culls if the number of items in the list is odd?

As you have effectively a 0 or a 1 answer you can shift the list by that negative number (make sure you have Wrap set to False)

 

Actually it would seem that this takes each odd number and makes it even by subtracting one. What I'm trying to do is: if there is an odd number of items in the list, cull the last item. I know how to cull the last item of a list, but I don't know how to only cull the last item if there is an overall odd number of items. Thanks for your help and a clever solution!

No. I am showing you the list length not the number.

The list (if odd in length) is being reduced by loosing the last item. Focus on only the highlighted part.

You have already concluded if the list contains odd or even items this is what goes into S (but as a negative)

I figured it out! You test the number of items in the array for being odd, and that will give you a true or false. Then you take a Dispatch component (didn't know that one) and input the boolean into the dispatch pattern, and input the array list into the list. Then you connect the "a" terminal of the dispatch into a cull component to cull the last item. Boom shaka-laka. Thanks for the help!

Well done for figuring it out.

As with everything in Grasshopper there is always more than one way to achieve a solution. But in this case a single GH component does the job rather than 4 separate ones, unless your aren't trying to merge the lists back together 

 

Oh...I see what you mean. Thanks a bunch, Danny.

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service