Variable xyz in formula (eval)

Dear all,

Some time ago I actually had the same problem and solved it, but I can not remember anymore how…

What I want to do is having a slider for x, y, z put this in a function and get the current {x,y,z}, in this manner as output.

Does anyone know how I can generate ‘text’ ( { and , ) to create this output? (Math–>Script–>Evaluate Function)

For example now I’m trying to input this as formula:
Format( “{0},{1},{2},{3},{4}”, “{”,x, y, z,”}”)

Kind regards,
Brigitte

I solved it:

Format( “{”&x&";"&y&";"&z&"}" )

Super important that whilst typing the " doesn’t change (automatically) to a slightly more to the right or left version, because the component doesn’t recognise this.

Hi Brigitte,

you can use the Format component (but you can also use the Format() method in the expressions if you want.

I don’t think you understand how formatting works based on your solution. What you do is provide a formatting pattern, which contains one or more indices in curly braces. These indices are then replaced by the actual values you have. So if you have three numbers called x, y, and z (with values 1.2, 2.5 and 4.87 for arguments sake) you can format them using the following expression:

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

which should yield (1.2, 2.5, 4.87).

You can also plug the x, y and z values into the Format component inputs, in which case you only have to supply the pattern text, which is "({0}, {1}, {2})".

Alternatively you could create the text just by concatenating the values. In an expression this would look like:

"(" & x & ", " & y & ", " & z & ")"

I find such a notation always very difficult to read.

Another benefit with the formatting approach is that you can specify formatting hints. For example if you want all the coordinate numbers to have exactly 3 decimal places, you can use the pattern "({0:0.000}, {1:0.000}, {2:0.000})", which would yield "(1.200, 2.500, 4.870)".

One final thing, if you want to have curly braces in your result, you’ll need to use double-curly-braces in the pattern. So "{{{0}, {1}, {2}}}" yields "{1.2, 2.5, 4.87}"

1 Like

Hi David,

Many thanks for the elaborate response, indeed I don’t think I fully understand formatting even up until today hahaha.

Looking back now, the Concat tool is a much more simple and useful way to get this same result I was looking for. :wink: