0
Evaluating a function with variables from an external file?
New Here
,
/t5/after-effects-discussions/evaluating-a-function-with-variables-from-an-external-file/td-p/12605473
Dec 19, 2021
Dec 19, 2021
Copy link to clipboard
Copied
I have the following expression I need to use over 144 layers. I want to store it somewhere so if I need to change the expression, I don't have to modify all 144 layers:
function loadColorBar(month) {
eval("var tempAnomaly=" + footage("AnnualTempAnomalies.json").sourceText);
//indexes: 0 - Jan, 1 - Feb, etc.
eval(" MonthData = (tempAnomaly[month].col" + thisComp.layer("Root").effect("Year")("Slider") + "+3.5)*100");
sampleRadius = [1,1]
return comp("Gradient Scale").layer("gradient").sampleImage([MonthData,5],sampleRadius)
}
I've loaded the file into After Effects and am trying to use the following eval expression:
eval(footage("ColorBars_GlobalFunctions.txt").sourceText);
loadColorBar(0);
Unfortunately it's throwing "ReferenceError: month is not defined"
This is telling me it's able to reference the file and it's found my function, but it's not liking the fact that my function is holding a variable. Any ideas how I can make this work? I feel like I'm so close to a solution!
TOPICS
Error or problem
,
Expressions
,
Import and export
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Have something to add?
Join the conversation

