Grasshopper

algorithmic modeling for Rhino

Hi,

Do somebody know how to change characters of numbers to another ?

For example:     List:        From         341       342      343      344

                                    To:           341       1      343      1           

Any ideas ?

Miklos      

Views: 1177

Replies to This Discussion

I don't get it, what's the logic behind the change?

--

David Rutten

david@mcneel.com

I guessed you meant to replace all even numbers with 1 ... :

Yes quiet, but actually to change numbers with last place-value of 6 (456,876,216..etc).

Where can i learn the usage of the comand "expression" ?

Here and now is as good a time and place as any.

Expression is an instruction to do something that will return a value.

They crop up in GH in a few places as components [Expression] and [Evaluate] and also as an I/O Modifier.

If we take yours as an example. You want to see if a number ends with "6" and return 1 in its place if it does.

If we focus on the bold type in that statement you will see that already our expression is taking shape.

[IF] .... [NUMBER] ... [ENDS WITH "6"] ... [RETURN "1"]

as the correct syntax for the Expression Component is:

If(Endswith(x,"6"),1, x)

To break this down to more of an understandable level we have

an expression within an expression

The If Expression is If(TEST,A,B) which means that if TEST is TRUE return A, otherwise return B

and the Endswith expression is Endswith(s,a) which means that if the string s ends with "a" then be TRUE otherwise be FALSE

So our Endswith is our TEST condition in the If expression, the A is 1 and the B is our original value*

All the expressions available in GH can be found using the Button in the top right hand corner of the Expression Editor which looks like f:N=>R

* you should be aware that our original value has been converted to Text in order to work within this expression. If you need to keep the original number you may need to create a Boolean List of 1s and 0s to manipulate the original values elsewhere

It was really helpful, thank you !

I tried this but somehow every number are shown in my list exept the numbers with place value 6 at the end ? Why is this happening ?

You're going to have to give me a little more than a statement of "it's not working".

Screenshot?

Definition?

Here is a screenshot...

Attachments:

All of your strings have a zero at the end "1.0", "2.0", "6.0"

Try converting them to Integers by passing them through an [Int] Param

Ah, why didn't you ask for that in the first place?
See if this is what you want (I'm using a regex expression (.*6$) on the numbers (as text/string)):
the MatchText component can be found under Sets>Text.
If you open the Expression Editor/Designer, click on the last icon in the top row : f:N->R for the function list.

Edit: Danny's aprroach is much simpler, but if I recall correctly somebody already handed you that solution, so I tried sth different:)

Attachments:

Well Danny's approach is also new for me as yours, so nothing is simple right know for me.

I must analyse them, hopefuly it will get "simplier" for me too. :)

Thank you !

I think that particular answer was in relation to culling everything except the Endswith 6 numbers and is only part of the puzzle.

This is more about embedding an expression within an expression in order to return a specified value for the Endswith numbers.

The issue here is that it's more of a wasgij than a jigsaw puzzle :)

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