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

Master Expression for Multiple Layers

Explorer ,
Aug 09, 2017 Aug 09, 2017

Copy link to clipboard

Copied

Working on a project that may have many hundreds of layers, and while many will have the same animations with time offsets etc I need to build it as an adjustable template.

Effectively I'm looking for a way to have many layers using the same expression from a single control layer so that if I want to make modifications to the expression I don't have to go through 100+ layers and re-paste the expression.

Ideal scenario would be to have an "Master Expressions" layer which has many properties with the applied expressions and then on all my other layers have them pull the expression code from the appropriate "Master Expressions" property. This way when I update the code in the "Master Expressions" it is applied globally across all linked layers.

I've attempted to use a Text Layer and input my expression in the "Source Text" parameter, but I have not found a way to pull the full text as applied expression for another layer.

Any ideas?

TOPICS
Expressions

Views

8.2K

Translate

Translate

Report

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

Community Expert , Aug 09, 2017 Aug 09, 2017

Say you have a text layer named "expression" with this text:

freq = 1;

amp = 100;

wiggle(freq,amp)

Then you could have this expression in another layer:

txt = thisComp.layer("expression").text.sourceText.value;

eval(txt)

Dan

Votes

Translate

Translate
Community Expert ,
Aug 09, 2017 Aug 09, 2017

Copy link to clipboard

Copied

Say you have a text layer named "expression" with this text:

freq = 1;

amp = 100;

wiggle(freq,amp)

Then you could have this expression in another layer:

txt = thisComp.layer("expression").text.sourceText.value;

eval(txt)

Dan

Votes

Translate

Translate

Report

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
Explorer ,
Aug 09, 2017 Aug 09, 2017

Copy link to clipboard

Copied

Thanks Dan!

You got me 99% there! One thing I found I needed to add around the expression in the text layer is triple quotes around the whole expression so that it behaved properly.

ie:

"""

freq = 1;

amp = 100;

wiggle(freq,amp)

"""

Votes

Translate

Translate

Report

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
Explorer ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

Hi,

I tried your trick (and it worked! Thanks!) but I would like my text layers to be stored in a different composition. I typed in:

txt = comp(exp).layer("expression pos").text.sourceText.value;

eval(txt)

but all i get is an error stating that "the property or method named 'exp' in Class 'global' is missing or does not exist."

What is weird is that it obviously finds both my composition, and my text layers, as the expression changes when I rename said layers. For instance, if I were to rename "expression pos" in the composition "exp" to "layerboy", the expression would change to:

txt = comp(exp).layer("layerboy").text.sourceText.value;

eval(txt)

Any ideas...? By the way, I'm way new at this. Appreciate your help so far.

Votes

Translate

Translate

Report

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 ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

if "exp" is the name of the composition, then it would be like this:

txt = comp("exp").layer("expression pos").text.sourceText.value;

eval(txt)

Dan

Votes

Translate

Translate

Report

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
Explorer ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

Thank you so much!

Votes

Translate

Translate

Report

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 ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

I've got a very similar situation, but am getting am getting the error, "undefined value used in expression (could be an out of range array subscript?)...

 

I have a comp called "Expressions". Within that comp, I have a layer called "Truck Wheel Position". In that null layer's position property, I've got the expression written as follows:

 

freq = 6;
amp = 3;
[position[0],wiggle(freq,amp)[1]] 

(The purpose here is to wiggle the position on the "y" value only, which works on the null layer with the expression.

 

In a separate composition, I've got several shape layers with the expression written as follows: 

 

pos = comp("Expressions").layer("Truck Wheel Position").transform.value;
eval(pos)

 

This returns the error mentioned above...

Any ideas on how expression could be fixed? 

Votes

Translate

Translate

Report

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 ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

eval() is expecting executable javascript text as its argument, and it looks like maybe you're trying to pass it your position expression, but there's no way for an expression to access the actual text of another expression applied to a property. You need to point it to the expression in text form somewhere (depending on what you're trying to do).

Votes

Translate

Translate

Report

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 ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

LATEST

Ah, that actually helped a lot! I was misunderstanding the use of the examples above, but I've got it working now. 

 

I was attempting to set the expression within the desired property of my "master expression layer", but I now realize that we're simply copying the literal text of a text layer into our desired layer's property expression.

Votes

Translate

Translate

Report

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 ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

Also note that with the new json features of After Effects, you can share expressions code much cleaner. See this tutorial:

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

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