Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

setting / animating properties on multiple layers via an expression and for loop

Community Beginner ,
Dec 01, 2021 Dec 01, 2021

Hello!

 

I'm working on a comp with dozens of layers / copies of a given precomp and I'm wondering whether it's possible to animate properties on these many layers via an expression and a for loop. Ideally, I would like to put the expression with the loop on a null object on a single layer that would then reference all of the copies. I imagine this might work with an array of layer references?

 

So far, I have only found a way to acheive the affect without a loop. I can copy-paste the expression on each individual layer, but this becomes tedious from a workflow / iteration standpoint. If I want to edit or change the expression, I need to copy-paste the new expression into layer one-by-one, which is not ideal.

 

Is it possible to set properties on a layer from another layer, without needing to have the expression on the actual layer?

 

Here is my expression that I would like to run through a loop. Currently it's on each individual layer's Time Remap property:

// get the offset value from the ctl layer
$offset = thisComp.layer("Ctl").effect("TimeOffset")("Slider");
// define the layer to sample from
$sampleTarget = thisComp.layer("Gradient");
// sample the R channel from the layer
$sampleVal = $sampleTarget.sampleImage(transform.position, [0.5,0.5], true, time)[0];
// do math to set current frame
$customTime = time + ($offset * $sampleVal);
// set the current frame
[$customTime]

 

Here is a screen recording of my comp where I explain how the layers work.

https://streamable.com/0wmvkz

 

Thanks!

TOPICS
Expressions , Scripting
995
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 01, 2021 Dec 01, 2021

AE auto-matches properties, so pasting updated expressions in bulk is not at all an issue. All that is required is that time-remapping is enabled and the property exposed, even if it only contains a dummy keyframe or expression so it can be quickly revealed based on all layers selected and hitting UU or EE. That's a basic workflow and there's no reason to make it more complicated than that. With that being the case, all your expression requires in terms of extra smarts is some provision that it

...
Translate
Community Expert ,
Dec 01, 2021 Dec 01, 2021

An expression can only calculate the value of the property it is applied to. Expressions cannot change values of any other properties. If you want to change many values, you can write a script (that can loop over properties and set expressions or values of them).

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 01, 2021 Dec 01, 2021

Thanks @Mathias Moehl!

 

I've never used scripts in After Effects so bear with me.

 

I noticed this video you posted in another discussion:

https://www.youtube.com/watch?v=sMxQawzvPXI

 

My questions...

 

  1. If I went this route, would then each layer / property need to have an expression which references the script file and calls the function?
  2. Is there a technique / script to batch-edit expressions on multiple layers without having to copy-paste them one-by-one?
  3. In my case, do I still need to put the expression on the Time Remap property? Or could the script change the property without needing an expression on the property?
  4. How would I pass a reference of the specified layer into the function as an argument?

 

David

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2021 Dec 01, 2021

1, yes

2.with iExpressions you can apply an expression to all selected properties. Even without any script, you can right-click on a property, choose "copy expression only" and then select all props and do a paste.

3. if the expression should change time-remap, it needs to be applied to time-remap

4 the layer to which the expression is applied is available in the variable "thisLayer", which can also be passed to function calls.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 01, 2021 Dec 01, 2021

AE auto-matches properties, so pasting updated expressions in bulk is not at all an issue. All that is required is that time-remapping is enabled and the property exposed, even if it only contains a dummy keyframe or expression so it can be quickly revealed based on all layers selected and hitting UU or EE. That's a basic workflow and there's no reason to make it more complicated than that. With that being the case, all your expression requires in terms of extra smarts is some provision that it is "aware" of its position, index or whatever is a unique criteria which in your case already would be established by simply letting the sampleImage() reference the layer's own position. So to sum it up: You don't need any scripts or alternative convoluted methods, you just need to work with basic AE functionality that already existed even before the dedicated "Paste Expression only" and otehr such functions were even introduced. some stuff in AE is smarter than people give it credit for...

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 03, 2021 Dec 03, 2021
LATEST

Thanks @Mylenium !

 

Using "EE" and "Copy Expression Only" are good tips.

 

However, I cannot seem to find a way to remove expressions on the same property on multiple layers. I can go Animation > Remove Expression if I have one layer and one property selected, but if I try to select multiple layers, I cannot remove the expression. I need to select each individual property on each layer one by one for it to work, which is not ideal.

 

I managed to find this script which seems to do what I am looking for with regards to batch editing expressions and removing expressions.

https://aescripts.com/pt_expressedit/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines