Grasshopper

algorithmic modeling for Rhino

First off, let me say how much I love the string/number formatting components in grasshopper 9.0014. I have gotten a lot of use out of them, but the lack of detailed explanations or reference makes it a pain to use sometimes. I recently found this great post:

http://www.grasshopper3d.com/forum/topics/formatting-numbers-in-gra...

which points to the msdn .net framework standard numeric format strings:

http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

and the custom ones too:

http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

Sooo... today I was trying to make a 2D array generator for RGB values to use with a RGB LED and an Arduino. For instance, declaring a 2D array in Arduino:

int color[3][3]={{255,0,0},{0,255,0},{0,0,255}};

I'm using the blend color component to spit out transitions between two colors. I want the list in the panel to be in the format above, so I used both the expression component and the string format component (are they the same under the hood?). In any case, if I have R, G and B values coming into the component, I want to format them so the come out looking like {R,G,B}, so I can just copy the output in a panel and paste it into the Arduino IDE. But what about {curly braces}. If the expression/format component uses them in it's syntax, for instance:

Format ("{R:0},{G:0},{B:0}",R,G,B)

how do I get them into the formatting string? I tried escaping them like:

Format ("\{{R:0},{G:0},{B:0}\}",R,G,B)

but that just makes the component angry

Escaping characters is explained in the formatting references above. Is it implemented in this component? Should I be looking at a different approach?

I've included a sample file below.

Thanks!

~BB~

Views: 10016

Attachments:

Replies to This Discussion

Hi Brett , hope I understood you correctly:
"{"&R&","&G&","&B&"}"

Awesome, that works! When I looked at the msdn reference, I thought I could only use {} to insert values into the string. So ampersands work too??? Can you point me to documentation of this?

Thanks very much!!

~BB~

If you want to add a curly bracket into a formatted string, make it a double one:

("{{{0}}}", x)

will give you

{x}

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Here's another way to do it.

Format("{{{0},{1},{2}}}", R, G, B)

should do the same.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Nice! Ok, but I don't know where to look to understand the available syntax to make these wonderful expressions. Is this a straight .net thing? I'm not googling the right thing..

I've never found a single comprehensive source for formatting rules.  This is just basic string combining with the observation that the curly brackets are special characters and have to be placed into the component through variables. 

Oh, I should have said that David is the best comprehensive source of formatting rules ;).

I bet! :)

I found this awesome topic and I would like to add a question regarding the formatting rules.
How could I delete or replace a character within a given string?
Let's say, can I use the component to get:
T{5;0;2}
into:
[5,0,2]
without having to use the Replace Text component?
Thanks anyway!

Nope, formatting cannot be used to modify strings, all it does is insert data into a string template.

You can use expressions to perform the replace, but not the Format method/component.

Thanks, David.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service