Grasshopper

algorithmic modeling for Rhino

Help!  What does the syntax in bold, red font below mean?  It is left as a default entry in the Maths>Expression component in Mac RhinoWIP GH.   I have looked at it and tried various options, but cannot figure out what it is doing or how to control it.

Format("{0}, {1}", x, y)

What do the integers in brackets within the quotes decode to?  Is there a decoder ring somewhere that tells me how to use this "Format" function?

What I am trying to understand is if a suitable string can be built up by algorithm from within GH and input to the Split and RelItem components to select paths and/or indexed items from a data tree.

I am working with Grasshopper in RhinoWIP on Macintosh.

Views: 1049

Replies to This Discussion

Format operates just like the dot net String.Format method - it's quite versatile and useful. I agree its functions are not the most easily discoverable in a Grasshopper context! The function's first argument is a format string containing special placeholders {0} {1} {2} etc., which in turn correspond to the following arguments in order. In the case of the Format component these correspond to each of its variable inputs.

In addition to specifying the placeholder by index like "{0}" you can also supply various format modifiers for different data types. Most commonly, you can format a number with a certain number of decimal places, but it also lets you do currency-formatted displays, dates and times, etc.  For example, to force a number to display 4 decimal places, you could use {0:0.0000} as a placeholder in your format string. Before the ":" is the index as before; after the colon is the format you want applied. 

Google "C# string.format syntax" to learn more. here are a few resources listing some of the many possibilities: 

https://www.dotnetperls.com/format

https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx

Wow!  That looks great.  Gives me plenty to do tonight figuring this all out!

Thanks for the reply.

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