The Expressions Thread

Hey guys, I’m looking for an expression to “Ease Ease” all keyframes of an effect, to make easy for begginners to edit a new template I’m working on, is this possible ? Basically I want all keyframes to be eased, no matter how many are there.

var keyNumb = thisProperty.numKeys;
var finValue = 0;

for (i = 1; i <= keyNumb - 1; i++) {

	finValue += ease(time, key(i).time, key(i + 1).time, key(i).value, key(i + 1).value);
	
	if (i == 1 || i == key(keyNumb).index) {

		finValue += 0;
			
	} else {

		finValue -= key(i).value;
			
	}

}

finValue;

This expression will easy ease all the keyframes in the property, you just need to copy and throw it in the property.
If you wish, you could change the ease function to easeIn or easeOut functions.

Let me know if that’s what you’re looking for.

2 Likes

Works great ! Thank you very much!

Actually just noticed a problem, this turns the animation into a straight line ):
Is it possible to ease through expressions keeping the original animation path ?

That should work:

keyNumb = thisProperty.numKeys;
finValue = 0;

for (i = 1; i < keyNumb; i++) {

	kt1 = key(i).time;
	kt2 = key(i + 1).time;

	finValue += thisProperty.valueAtTime(ease(time, kt1, kt2, kt1, kt2));
	finValue -= (i == 1 || i == key(keyNumb).index) ? 0 : key(i).value;

}

if (keyNumb == 0) finValue = value;

finValue;
2 Likes

Hello, I’m trying to add an expression to the anchor point value but I’m getting an error and I don’t know why
The expression:

x= content(“Rectangle 1”).content(“Rectangle Path 1”).size/-2;
y= 0;
[x,y]

And thats the error: “After Effects warning:array piece can’t expand to more than one value”

Anyone knows how to solve it ?

x= content("Rectangle 1").content("Rectangle Path 1").size[0]/-2;
y= 0;
[x,y]

This should work. What you were doing wrong is assigning the x variable’s value to the size property which its value is already an array of two elements. Instead, you should be specifying which element of the size array you want the x variable to have.

1 Like

Thank you!

1 Like

Hi all, I’m new for AE expression
So I want to control position from other comp using “Point Control”
I used simple parent expression like this

comp(“Comp 2”).layer(“Comp 1”).effect(“Point Control”)(“Point”)
Everything works well (Image 1)

But when I offset Comp 1 to the right side (Image 2). The changing position didn’t match with the keyframe. I got couple seconds delay. So what should I do to make to make changing position exactly the same with the keyframe no matter how much I offset the comp 1.

Sorry, if my English isn’t good.

Cheers :slight_smile:

Try this:

var layer = comp("Comp 2").layer("Comp 1");
layer.effect("Point Control")(1).valueAtTime(layer.startTime + time)
1 Like

Perfectly work! Thank you so much !! :slight_smile:

1 Like

First off thanks for taking the time to review my question, all help is immensely appreciated. I’ve been building my first AE template project, it is a slideshow/opener and I’m running into some problems with expressions. Specifically I have several effect controllers that control various effects like BG color with expressions. All controls work perfectly. BUT if a client buys the template and wants to duplicate comp, to add more slides to the slide show, then the expressions still reference the original comp not the new comp. I’m pretty new to expressions, and have been searching forums for a few days to find a way where a client can duplicate a comp and have the expressions reference the new duplicate comp so they do not run into expression error. In general how do you all set up your slideshow templates so that the various slides/scenes can be duplicated without causing expression errors.
To be more specific I call my main comp “Render”. Inside of Render are my various slide comps, arranged in a modular structure. Inside each slide I have a null layer named “Effects Controller”. when pickwhipping attributes to the controllers on the layer “Effects Controller” which is always the first layer, I have updated the expression so that it refers to the index of the layer not name,
thisComp.layer(1).effect(“Text 08 Animation Shadow”)(“Shadow Color”) which works just fine, except for nested precomps. I have several nested precomps that have color shapes inside of them, and I have the “fill” of each pickwhipped to a color controller on the effects controller layer, but because they reside in a precomp, using thisComp.layer(1) obviously wont work. Thus Ill have to refer to the comp by name, which wont update if the comp is duplicated. I’m sure there is an easy solution I have not thought about, but any ideas regarding this would be greatly appreciated. Thanks

I came up with a workaround for a similar problem I ran into around half a year ago. Not ideal though.

Just to be clear, I’ll be referring to the comps you have in your “Render” comp where you have the controller null layer as “slide comps”.

  • Rename the slide comps so that you have a number at the end of their names. For example something like this would work: “Slide Comp 001”, “Slide Comp 002” etc. So when the user duplicates the comp, After Effects will add one to the number at the end and assign the new name to the new comp. We’ll benefit from this feature.

  • Rename the precomps where you have to refer to the slide comp by name so that they reflect the number of the slide comp that contains the controller layer. Say for example that you use two precomps inside a slide comp, the two precomps should be named like this: “Precomp 1 Slide Comp 001”, “Precomp 2 Slide Comp 001”.
    So that when the user duplicates a slide (keep in mind the user will have to duplicate every precomp that’s being used inside the slide that the user wants to duplicate), the main comp and all of the precomps inside of it will have the same name as the original copies but with 1 added to the numbers at the end.

After you do those two steps, if you go inside a precomp of “Slide Comp 001” and pickwhip a layer’s property to a color controller on the controller layer inside of the slide comp, you should get expression that looks something like this:

comp("Slide Comp 001").layer(1).effect("Color Controller")(1)

We need to change it to this:

comp("Slide Comp " + variable).layer(1).effect("Color Controller")(1)

We’ll get the variable’s value from the precomp’s name (which is for example “Precomp 1 Slide Comp 001”):

targetCompName = "Slide Comp";  //change this to the name of the comp that contains the controller without the numbers at the end

substrings = thisComp.name.split(' ');
compName = targetCompName + " " + substrings[substrings.length - 1];

comp(compName).layer(1).effect("Color Controller")(1);

This expression basically cuts the numbers at end of the precomp’s name and adds them to the targetCompName variable that you specify manually.

Not an easy workaround, I know, but I hope that makes sense.

Thanks Osama Sayegh, for taking the time to reply. This looks like a great work around, I’ll try it this afternoon! and thanks for the detailed explanation on how the expression works, you made it easy to follow. Hopefully I can find a renaming script to easily rename my comps. I’ll let you know how it works.

1 Like

Make a backup copy of your project before you run any script or test my workaround, just in case something goes wrong. :slight_smile:

I’ll definitely make a copy, ran into that problem before no fun. So in regards to the expression do the “” at the end of the comp names matter and do the amount of words in the precomp name matter for the expression, or does the ending part of the precomp name that references the comp with the controller the part that matters for the expression. For example if my comp is titled “Slide 20” and my precomp is title “Color Wipe Slide 20” will the expression work eventhough Color Wipe is two words vs precomp being one word.
Also just to wrap my head further around the expression how does the expression determine where to split/separate the name. Does it do it by word? and substring.length, does length refer to the amount of distinguishable words. Hope I’m not taking too much of your time with my questions, just trying to understand the expression for future applications. Also for taking the time to help me if there is a way to give back to the forum please let me know.

No, the “” at the end of the comp names don’t matter at all. But in the code they matter. We use them to tell the computer that whatever between them is text.

Amount of words doesn’t matter, but the ending part does. The comp/precomp name has to end with a white space character " " and then a number.

Yes it will work if the targetCompName variable is assigned to “Slide”.
targetCompName = "Slide";

The split() method breaks the string at the character I specify between the double ’ inside the parentheses. Which is essentially a white space character. So if you give it “Color Wipe Slide 20” it returns the following array:

["Color", "Wipe", "Slide", "20"]

In the expression, the array that the split() method returns will be assigned to the substrings variable. Since there must be number at the end of the precomp name, we’ll always need the last element of the array. And this is when

substrings[substrings.length - 1]

comes into play. Basically it says tell me what the last element of our array is. And then we add the last element to the targetCompName variable that you need to assign a value to it manually, which has to be “Slide” in your example.

Now if your comp is actually titled “Slide 20” and your precomp name ends with " 20", this expression should work.

targetCompName = "Slide";  //change this to the name of the comp that contains the controller without the numbers at the end

substrings = thisComp.name.split(' ');
compName = targetCompName + " " + substrings[substrings.length - 1];

comp(compName).layer(1).effect("Color Controller")(1);

Thanks for walking me through the expression, makes perfect sense now. I greatly appreciate all of your guidance and help. Its great to see people, like your self, taking time to help the community!

For anyone who might be reading this, I have found the script “AE Global Renamer” by Lloyd Alvarez which easily renames your comps if need be, as well as pt_ExpressEdit2 By Paul Tuersley which allows you to edit several, or all of your expressions at once.

  • cheers
1 Like

Morning Osama,
Got many of the expressions to work using your work around. A few have not, and I’m not sure why. One of my comps is called “Intro 00” so in your expression, I changed “Slide” to “Intro” for targetCompName, but I get the error saying comp “Intro” does not exist, so for some reason its not adding the suffix 00 to the end, but I cant seem to figure out why. It has also done the same error on a few “Slide” comps as well, even though the precomp name ends with the same name and sequence as the main comp.

here’s an example of expression and error message.
this expression is applied to layer “Left Animation Photo 03 Slide 03”
and its in comp “Slide 03”

targetCompName = “Slide”; //change this to the name of the comp that contains the controller without the numbers at the end

substrings = thisComp.name.split(’ ');
compName = targetCompName + " " + substrings[substrings.length - 1];
comp(compName).layer(1).effect("Photo 11 Left Shadow ")(“Direction”)

image

not exactly sure why its not working, in theory it should. Thanks again for your time.

Remove the space at the very end of the comp name, that should fix it. :wink:

image