Grasshopper

algorithmic modeling for Rhino

Hi there, i'm trying to make a example of how does the tree branches are working, what does 'graft' and "flat". I prepared simple GH definition but i have problem with formatting datas and combining them into one line that contains information about the object type, branch and item index. The result should be that all elements in rhino viewport have short line with that description.

for example each point has description like p{0,0,2)i6 which means point{branch}index 6  (see jpg)


I used formula format("0"),x for 3 variables (type,branch,index) but i dont know how write it to make it works. Does anyone has an idea how it should looks like ? Any help is welcome ! Thank You.

Adam Chalupski

Views: 1494

Attachments:

Replies to This Discussion

Hi Adam,

 

the Format() function is basically a very advanced Find/Replace function. What happens is that all the format blocks in the format pattern (the string that looks like "{0}...") are replaced with the associated data (x, y or z).

 

So, whenever there's a format block with a zero inside curly brackets ("{0}") the value of the first piece of data (x in this case) is inserted in that location. If the format block contains another number, say {2}, then the third piece of data is inserted there (z in this case).

 

So, when the function looks like this:

 

Format("{0}({1}) i{2}", x, y, z)

 

you can imagine it as three find/replace operations:

 

replace "{0}" in "{0}({1}) i{2}" with x

replace "{1}" in "{0}({1}) i{2}" with y

replace "{2}" in "{0}({1}) i{2}" with z

 

thus, giving you

 

"x(y) iz"

 

Furthermore you can add additional constraints on how values like x, y and z are pasted into the pattern. For example you can enforce a specific numeric formatting (scientific notation, or hexadecimal notation), or a specific time and date formatting (depending on current culture settings) or even customized formats. However, since you don't seem to need these, I'll skip over them for now.

 

Does that explain to your liking how Format() behaves?

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi Adam,

in addition and for more documentation, you can also refer to .Net's String.Format function, which is the implementing method for Grasshopper's Format function.

- Giulio

______________

giulio@mcneel.com
McNeel Europe

Thank You, David and Giulio the Format("{0}({1}) i{2}", x, y, z) works with my example. For now its all I need although some of the formated descriptions are very long and thus the result is hard to read.

Now I have to work a little bit more with finding the way of how to automaticly detect what sort of object is connected to my claster. 'Panel' displays points as a string of {x,y,z}  but they should all become displayed as p.
it looks like that..
Attachments:

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