The Expressions Thread

Hi Folks, I want to make a wiggle only in Y position, but my expression doesn´t work:

x = value [0];

y = wiggle(20,20);

[x,y]

What am i doing wrong? Thanks!

temp=wiggle(20,20);
//[value//[0],temp//[1]]

delete this //

Thanks!

DiegoMirnov said

Hi Folks, I want to make a wiggle only in Y position, but my expression doesn´t work:

x = value [0];

y = wiggle(20,20);

[x,y]

What am i doing wrong? Thanks!

Try this:
y = wiggle(20,20);
[value[0],y[0]]
Your expression don't work because wiggle in property with two values also has two values. So you need to put [0] or [1].

UPD: Sorry, I'm too slow :)
DOGmotion said
DiegoMirnov said

Hi Folks, I want to make a wiggle only in Y position, but my expression doesn´t work:

x = value [0];

y = wiggle(20,20);

[x,y]

What am i doing wrong? Thanks!

Try this:
y = wiggle(20,20);
[value[0],y[0]]
Your expression don't work because wiggle in property with two values also has two values. So you need to put [0] or [1].

UPD: Sorry, I'm too slow :)

Awesome, thanks Dog!

Hi, guys I’m working on a project where I d like to link the text value to a specific attribute, such as opacity.

It it possible to link for example the letter ‘t’ to 50% opacity, or a specific position, and the letter ‘b’ to an other value? So when the text layer is set to ‘t’ the opacity is 50% for example, and when it’s ‘b’ the opacity is 80%.

Thanks! :slight_smile:

NeuronFX said

Hi, guys I’m working on a project where I d like to link the text value to a specific attribute, such as opacity.

It it possible to link for example the letter ‘t’ to 50% opacity, or a specific position, and the letter ‘b’ to an other value? So when the text layer is set to ‘t’ the opacity is 50% for example, and when it’s ‘b’ the opacity is 80%.

Thanks! :slight_smile:

Try this:

text = thisComp.layer("TextName").text.sourceText.value; // Change the layer name
text = text.toLowerCase();
switch (text) {
\tcase 'b': 30; break; // Change 30 to have another value when your text = "b"
\tcase 't': 50; break; // The same thing with 50 and text "t"
\tdefault: 0; // Default value
}

This expression works with both uppercase and lowercase letters (“t” and “T”). So the value on “T” will be the same as on “t”. If you don’t want this, remove this line:

text = text.toLowerCase();
DOGmotion said
NeuronFX said

Hi, guys I’m working on a project where I d like to link the text value to a specific attribute, such as opacity.

It it possible to link for example the letter ‘t’ to 50% opacity, or a specific position, and the letter ‘b’ to an other value? So when the text layer is set to ‘t’ the opacity is 50% for example, and when it’s ‘b’ the opacity is 80%.

Thanks! :slight_smile:

Try this:

text = thisComp.layer("TextName").text.sourceText.value; // Change the layer name
text = text.toLowerCase();
switch (text) {
\tcase 'b': 30; break; // Change 30 to have another value when your text = "b"
\tcase 't': 50; break; // The same thing with 50 and text "t"
\tdefault: 0; // Default value
}

This expression works with both uppercase and lowercase letters (“t” and “T”). So the value on “T” will be the same as on “t”. If you don’t want this, remove this line:

text = text.toLowerCase();

Thanks Yahor! Very easy to follow. Works like a charm :slight_smile:

Is there a way to specify the letter position in a word? For instance the source text will only take into account the third letter in a specific word? This would really be a time saver!

NeuronFX said
DOGmotion said
NeuronFX said

Hi, guys I’m working on a project where I d like to link the text value to a specific attribute, such as opacity.

It it possible to link for example the letter ‘t’ to 50% opacity, or a specific position, and the letter ‘b’ to an other value? So when the text layer is set to ‘t’ the opacity is 50% for example, and when it’s ‘b’ the opacity is 80%.

Thanks! :slight_smile:

Try this:

text = thisComp.layer("TextName").text.sourceText.value; // Change the layer name
text = text.toLowerCase();
switch (text) {
\tcase 'b': 30; break; // Change 30 to have another value when your text = "b"
\tcase 't': 50; break; // The same thing with 50 and text "t"
\tdefault: 0; // Default value
}

This expression works with both uppercase and lowercase letters (“t” and “T”). So the value on “T” will be the same as on “t”. If you don’t want this, remove this line:

text = text.toLowerCase();

Thanks Yahor! Very easy to follow. Works like a charm :slight_smile:

Is there a way to specify the letter position in a word? For instance the source text will only take into account the third letter in a specific word? This would really be a time saver!

Don’t quite understand what you mean.

But if you have, for example, the text “The quick brown fox jumps over the lazy dog”. And you want to set specific value if the first letter is “t”. So you need to change this line:

switch (text) {

to that one:

switch (text[0]) {

The counting starts from zero. For example, you want to check if the eleventh letter is “b”. You put text[10], not text[11]

BUT if there is only 4 letters in source text you will get an error. Because there is no eleventh letter.


So first you need to check how many characters you have in text. Here is the whole code:

text = thisComp.layer("TextName").text.sourceText.value;
num = 10; // Put here the number of desired letter. Remember counting starts from zero
def = 0; // Set default value
text = text.toLowerCase();
if (text.length > num) {
\tswitch (text[num]) {
\t\tcase 'b': 30; break;
\t\tcase 't': 50; break;
\t\tdefault: def;
\t}
}else def;

…or maybe you need something more complex?

@DOGmotion

That’s exactly it, brilliant! :slight_smile: I was trying to play with sourceText and range selector, but wasn’t getting anywhere.

Thanks a lot for your help Yahor, this is a real time saver! :slight_smile:

Hi Guys…i made a template in 30 fps,i want to convert it to 25 or 24 fps and include that for customer…how can i do it?Thanks in advance

Hello everyone, I have a question because I’m trying to character customization with expressions.
I mean to change clothes, hair color, hair type, etc.
I know that the controlling effect expressions are used to it, but not the syntax to use for this to work
I have not found any tutorial where you explain
Can anybody help me
thanks in advance

PaintSpraySounds said

Hello everyone, I have a question because I’m trying to character customization with expressions.
I mean to change clothes, hair color, hair type, etc.
I know that the controlling effect expressions are used to it, but not the syntax to use for this to work
I have not found any tutorial where you explain
Can anybody help me
thanks in advance

Hi Paint Spray. The syntax is basically the same as Javascript. You’ll find countless references to this language on the web. However, After Effects has its own set of commands too, which you can find under expression reference in the After Effects help. After Effects also has many of its own little foibles. Unfortunately these are best learned as you go along (and that can take a while), but just start trying out some simple stuff and you’ll soon get a feel for it.

If you ever need to see the results of your expression line by line, you can practice by writing expressions into the Source Text property of a text layer.

felt_tips said
PaintSpraySounds said

Hello everyone, I have a question because I’m trying to character customization with expressions.
I mean to change clothes, hair color, hair type, etc.
I know that the controlling effect expressions are used to it, but not the syntax to use for this to work
I have not found any tutorial where you explain
Can anybody help me
thanks in advance

Hi Paint Spray. The syntax is basically the same as Javascript. You’ll find countless references to this language on the web. However, After Effects has its own set of commands too, which you can find under expression reference in the After Effects help. After Effects also has many of its own little foibles. Unfortunately these are best learned as you go along (and that can take a while), but just start trying out some simple stuff and you’ll soon get a feel for it.

If you ever need to see the results of your expression line by line, you can practice by writing expressions into the Source Text property of a text layer.

Thanks Felt, I have not explained well in my previous post

Anyway I have been searching the net and I saw that I can do this using the effect Remaping time and combining with effect controller
now I find out what the line of code for that to work

PaintSpraySounds said
felt_tips said
PaintSpraySounds said

Hello everyone, I have a question because I’m trying to character customization with expressions.
I mean to change clothes, hair color, hair type, etc.
I know that the controlling effect expressions are used to it, but not the syntax to use for this to work
I have not found any tutorial where you explain
Can anybody help me
thanks in advance

Hi Paint Spray. The syntax is basically the same as Javascript. You’ll find countless references to this language on the web. However, After Effects has its own set of commands too, which you can find under expression reference in the After Effects help. After Effects also has many of its own little foibles. Unfortunately these are best learned as you go along (and that can take a while), but just start trying out some simple stuff and you’ll soon get a feel for it.

If you ever need to see the results of your expression line by line, you can practice by writing expressions into the Source Text property of a text layer.

Thanks Felt, I have not explained well in my previous post

Anyway I have been searching the net and I saw that I can do this using the effect Remaping time and combining with effect controller
now I find out what the line of code for that to work

It really depends on what you specifically want to do. But the expression you apply to a Time-remap property should give a result which is a number. This is the time in seconds of the layers source that you want to display at that frame.

For instance:

tPulloverStyle = effect("Pullover Style")(1).value; //an effect on the layer.
if(tPulloverStyle == 1) 0; else if (tPulloverStyle ==2) 2; else 4;

Hello,

I need some help, it’s very simple but I don’t get it:


If I have delayed animation like this:

  • delay = 4
  • thisComp.layer("White Solid 2 Comp 1").effect("Pos")(1).valueAtTime(time - delay);
  • …my animation will start at second 4.

    So if I want to change my time I have to edit my expression and change the “delay” value.

    …then I figured I could use “marker” position as “delay” value and movie it…

    So I got this:


  • n = 0;
  • if (marker.numKeys > 0){
  • n = marker.nearestKey(time).index;
  • if (marker.key(n).time > time){
  • n--;
  • }
  • }
  • if (n == 0){
  • value;
  • } else {
  • delay = marker.key(n).time;
  • thisComp.layer("White Solid 2 Comp 1").effect("Pos")(1).valueAtTime(time - delay);
  • }

  • My question is why do I need all those lines above "delay = marker.key(n).time", is there any way to use marker position directly as value for delay like this:
    "delay = marker.time" - I know that this is wrong but is there something like this that could read marker time and make it right "value" for the "delay".
    As I said it works fine with all those lines above but I would just like to understand it better.
    Thanks for your help!
    Best, 3Dspace

    Hi, 3Dspace.

    Actually this expression is not what you want to achieve.

    3Dspace said
  • n = 0;
  • if (marker.numKeys > 0){
  • n = marker.nearestKey(time).index;
  • if (marker.key(n).time > time){
  • n--;
  • }
  • }
  • if (n == 0){
  • value;
  • } else {
  • delay = marker.key(n).time;
  • thisComp.layer("White Solid 2 Comp 1").effect("Pos")(1).valueAtTime(time - delay);
  • }
  • With this expression your animation start from time = 0, and repeats again where marker was set. You can put several markers, and everytime animation repeats.
    So let's look closely:

    if (marker.numKeys > 0){
    This we need to check if there is markers. Without it there will be an expression error every time when you delete your marker. Highly recommend to use it when you work with markers or keys.


    n = marker.nearestKey(time).index; // find nearest marker
    if (marker.key(n).time > time){ // if marker time more then time...
    \tn--; // ...go to previous marker
    }
    So this code always "select" left marker between two nearest keys. Time goes from left to right (Captain Obvious!), that is why we need exactly left marker... Hope you understand what I mean.


    if (n == 0){
    \tvalue;
    } 
    n == 0 means that there is no "selected" marker, there is no markers before "current time", because first marker id is 1, and in previous code it was "right" marker. In this case animation start normally from time = 0.


    else {
    \tdelay = marker.key(n).time;
    \tthisComp.layer("White Solid 2 Comp 1").effect("Pos")(1).valueAtTime(time - delay);
    }
    This code you understand.

    And here is the expression you want:

    if (marker.numKeys == 0){ // If there is no markers....
    \tvalue; // ...animation normally start from 0.
    } else {
    delay = marker.key(1).time; // "select" first marker
    thisComp.layer("White Solid 2 Comp 1").effect("Pos")(1).valueAtTime(time - delay);
    }
    

    PS: Check all “–” symbols before copypaste the code. The forum do with them crazy things. )

    Thank you so much DOGmotion!!! You’ve explained it exactly as I needed it, now it’s all clear to me! :slight_smile:

    Thanks again!

    Best wishes!

    Hello, guys n girls maybe some of you know how to extract keyframes from wiggle effect ? In example I just make wiggle expression and then I want all the timeline to be covered with those actual keyframes and then delete the wiggle expression. How to do that ?

    Cyzer, may be script Smart Baker