Grasshopper

algorithmic modeling for Rhino

How would I replace values over a specified threshold with a specific value in a list?

I'm just kindof picking up grasshopper for my Masters of Architecture thesis and I'm having a problem figuring out the replace operator.

 

I have a set of lists in which I wish to replace all the numbers greater than 150 with 0. In my mind I need to find all the positions in the list that have values over 150, and then modify the original list to replace the numbers at those positions with 0. I can use the greaterthan command to create a list of true/false for each index position as to wether the value there is greater than 150, but I can't get this list to work with replace operator, which is what I think I need to do?

 

So essentially I've tried to use the greater than operator to create an index which I plug into the list's replace operator but it doesn't seem to work right. I don't think I really understand how the replace operator works. In some organizations I get it to replace the first two (index 0 and 1) with 0, but I can't seem to get it to replace all the "true" from the greater than index with 0.

I'm posting this on a computer without rhino/grasshopper because my laptop battery died and I don't have my power cord, so I can't post a screen capture of what I've tried. It seems like it should be a fairly basic problem though.

 

thanks for any help you can offer.

Views: 3599

Replies to This Discussion

You could apply an expression with a conditional:

If (x > 50, 0, x)

The If function takes 3 parts, the first part must be a True/False value. x is either larger than 50 or it isn't. If it is, then the second part (0) is returned. If it isn't, then the third part (x) is returned.

Thus, this expression keeps numbers below 50 intact but all numbers larger than 50 are replaced by 0.0

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank-you, this worked exactly like I wanted it to.

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