Concatenate texts

Moderators: Disciple, zlovatt

Post Reply
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

All I want to do is concatenate a few expression results.
Here's what I'm trying to do:

Code: Select all

R = thisComp.layer("CDL Lables").effect("CDL")("Red Slope");
G = thisComp.layer("CDL Lables").effect("CDL")("Green Slope");
B = thisComp.layer("CDL Lables").effect("CDL")("Blue Slope");
string=R, G, B
This only results in the R value being displayed. I've tried the + operator but that adds the values together rather than concatenating them.

The result I'm looking for would look like this: 1.234, 3.456, 7.890

Thanks
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

BTW, this is in the source text field of a text layer.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

You could do:

Code: Select all

string=R.value + "," + G.value + "," +B.value;
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

YES!
That's what I've been looking for but I couldn't get the code right.
I added a space after each comma and it works great.

I don't suppose there's any way to tell it to colorize each number separately, is there?
Ideally, I'd like the first number to be ... red, green, blue.

Thank you PT!
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

One more thing. Is there a way to limit the number of decimal places?
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

This will limit it to 2 decimal places:

Code: Select all

string=R.value.toFixed(2) + ", " + G.value.toFixed(2) + ", " +B.value.toFixed(2);
You won't be able to set individual text colors if you do this on a single text layer. When an expression is applied it appears to take the style from the first character of the layer's pre-expression state.

You could either:
a. If the text is against a transparent background (e.g. created in a precomp before composited) you could create some red, green and blue solid layers, set their Blending Mode's to Color, turn on Preserve Transparency and place them over the specific bits of text.
b. Set the initial color to red through the character panel, then add a text animator ("Animate" menu just above source text property) for Fill Color > RGB, set it to Green and change the start and end of the range selector to fit the specific characters. Duplicate that animator (Animator 1) and change it to do the same for blue.
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

Oh hell yeah! That rocks!

Thanks again. You're amazing!
Post Reply