ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to set global variables and/or Functions in composition

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Evan Jenkins
How to set global variables and/or Functions in composition
on Mar 29, 2020 at 6:40:47 pm

I have a massive piece of code that sets variables by referencing sliders in a control layer.

I have 30 layers where I apply this same piece of code. If I need to adjust the code, I have to delete 29 layers, and then re-do them all haha. It's crazy.

Is there some way to make my variables global, so those variables apply to all layers? Can I get a function to apply to all layers?

myID = effect("myID")("Slider");

firstPhotoInPoint = thisComp.layer("Control Sliders").effect("firstPhotoInPoint")("Slider");

checkSections = thisComp.layer("^sections").text.sourceText;

sectionOneStart = thisComp.layer("Control Sliders").effect("sectionOneStart")("Slider");
sectionOnePhtNum = thisComp.layer("Control Sliders").effect("sectionOnePhtNum")("Slider");
sectionOneDur = thisComp.layer("Control Sliders").effect("sectionOneDur")("Slider");
sectionOnePhtTime = sectionOneDur / sectionOnePhtNum;

sectionTwoStart = thisComp.layer("Control Sliders").effect("sectionTwoStart")("Slider");
sectionTwoPhtNum = thisComp.layer("Control Sliders").effect("sectionTwoPhtNum")("Slider");
myIDSectionTwo = myID - sectionOnePhtNum;
sectionTwoDur = thisComp.layer("Control Sliders").effect("sectionTwoDur")("Slider");
sectionTwoPhtTime = sectionTwoDur / sectionTwoPhtNum;

sectionThreeStart = thisComp.layer("Control Sliders").effect("sectionThreeStart")("Slider");
sectionThreePhtNum = thisComp.layer("Control Sliders").effect("sectionThreePhtNum")("Slider");
myIDSectionThree = myID - sectionOnePhtNum - sectionTwoPhtNum;
sectionThreeDur = thisComp.layer("Control Sliders").effect("sectionThreeDur")("Slider");
sectionThreePhtTime = sectionThreeDur / sectionThreePhtNum;

sectionFourStart = thisComp.layer("Control Sliders").effect("sectionFourStart")("Slider");
sectionFourPhtNum = thisComp.layer("Control Sliders").effect("sectionFourPhtNum")("Slider");
myIDSectionFour = myID - sectionOnePhtNum - sectionTwoPhtNum - sectionThreePhtNum;
sectionFourDur = thisComp.layer("Control Sliders").effect("sectionFourDur")("Slider");
sectionFourPhtTime = sectionFourDur / sectionFourPhtNum;

sectionFiveStart = thisComp.layer("Control Sliders").effect("sectionFiveStart")("Slider");
sectionFivePhtNum = thisComp.layer("Control Sliders").effect("sectionFivePhtNum")("Slider");
myIDSectionFive = myID - sectionOnePhtNum - sectionTwoPhtNum - sectionThreePhtNum - sectionFourPhtNum;
sectionFiveDur = thisComp.layer("Control Sliders").effect("sectionFiveDur")("Slider");
sectionFivePhtTime = sectionFiveDur / sectionFivePhtNum;

if (checkSections == "sections" && myID &lt;= sectionOnePhtNum) {
timeElapsed = sectionOnePhtTime * (effect("myID")("Slider") - 1);
timeStart = firstPhotoInPoint + timeElapsed;

} else if (checkSections == "sections" && myID &lt;= (sectionOnePhtNum + sectionTwoPhtNum)) {
timeElapsed = firstPhotoInPoint + sectionOneDur + (sectionTwoPhtTime * (myIDSectionTwo - 1));
timeStart = timeElapsed;

} else if (checkSections == "sections" && myID &lt;= (sectionOnePhtNum + sectionTwoPhtNum + sectionThreePhtNum)) {
timeElapsed = sectionThreeStart + (sectionThreePhtTime * (myIDSectionThree - 1));
timeStart = timeElapsed;

} else if (checkSections == "sections" && myID &lt;= (sectionOnePhtNum + sectionTwoPhtNum + sectionThreePhtNum + sectionFourPhtNum)) {
timeElapsed = sectionFourStart + (sectionFourPhtTime * (myIDSectionFour - 1));
timeStart = timeElapsed;

} else if (checkSections == "sections" && myID &lt;= (sectionOnePhtNum + sectionTwoPhtNum + sectionThreePhtNum + sectionFourPhtNum + sectionFivePhtNum)) {
timeElapsed = sectionFiveStart + (sectionFivePhtTime * (myIDSectionFive - 1));
timeStart = timeElapsed;

} else {

photoTime = thisComp.layer("Control Sliders").effect("photoTime")("Slider");
timeElapsed = photoTime * (effect("myID")("Slider") - 1);
timeStart = firstPhotoInPoint + timeElapsed;

}

valueAtTime(time - timeStart);


Evan Jenkins
Aspen Films Inc.
aspenfilms.ca


Return to posts index

Andrei Popa
Re: How to set global variables and/or Functions in composition
on Mar 29, 2020 at 7:10:28 pm

Create a text layer. Put all this code in the text value. And on all your layers put this as expression:

eval(thisComp.layer("Text Layer").text.sourceText)

I think you'll need to change the name of the layer. You can make it invisible so it does not mess with your design.

Andrei
My Envato portfolio.


Return to posts index

Evan Jenkins
Re: How to set global variables and/or Functions in composition
on Mar 29, 2020 at 7:35:53 pm

Thanks I copied and pasted my code into the text layer and then added the eval, but I got an error, it says Object of type TextProperty found where a Number, Array, or Property is needed

Evan Jenkins
Aspen Films Inc.
aspenfilms.ca


Return to posts index


Andrei Popa
Re: How to set global variables and/or Functions in composition
on Mar 29, 2020 at 7:44:43 pm

Maybe add .value at the end. Some of this small things changed with the expression engine.

eval(thisComp.layer("Text Layer").text.sourceText.value)

Andrei
My Envato portfolio.


Return to posts index

Evan Jenkins
Re: How to set global variables and/or Functions in composition
on Mar 29, 2020 at 8:01:30 pm

I think I'm making progress, now it says "Syntax Error"

The .value seemed to work.

Also I saw an old post on the forum where you can add """Code Here""" (triple quotes) in the text layer to make sure you're converting everything into a single character string.

I'm still working at it trying to resolve the error.

Evan Jenkins
Aspen Films Inc.
aspenfilms.ca


Return to posts index

Evan Jenkins
Re: How to set global variables and/or Functions in composition
on Mar 29, 2020 at 8:19:37 pm

I gave up out of trying to get the code out of a text layer, there was something wrong with what I was doing but I couldn't figure it out.

I actually had more success with getting the code out of the comments of a layer marker, which also has the advantage of letting me scroll through a little easier to access the code.

I got the idea from this video:







eval(thisComp.layer("Set Global Variables").marker.key(1).comment);

Evan Jenkins
Aspen Films Inc.
aspenfilms.ca


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]