ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Updating Source Text's values from a JS file

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Joe Richardson
Updating Source Text's values from a JS file
on Feb 5, 2018 at 1:56:09 am

Hello,

I wanted to have the Source Text print out the values from a JS every frame (60fps).

I've got all the values in a JS file. The expression for the Source Text is:


var path = "D:\\values.js";
$.evalFile(path);


The values.js code is:


var string = "Values,";
array = string.split(",");
l = array.length;
x = Math.floor(time*60);
if(x < l)
{array[x];}


This code can work, but it's based on the comp's length, I think. I just wanted the Source Text to update every frame (60fps) from when the layer starts.

Thank you.


Return to posts index

Joe Richardson
Re: Updating Source Text's values from a JS file
on Feb 6, 2018 at 5:51:59 am

Update: I found what I think is a solution posted here by Dan Ebberts: https://forums.creativecow.net/thread/227/15319#15321

The solution might be:


mySplit = txt.split(" ");
f = timeToFrames()
mySplit[Math.min(f,mySplit.length-1)]


However, I'm not sure how to transpose the code onto the .js file. I've been trying for a bit, but I can't get it to update right.

The text layer's Source Text expression is


var path = "D:\values.js";
$.evalFile(path);


values.js' code is:


var string ="255,255,255,93,93,93,93,93,91, ....... ";
a = string.split(",");
f = timeToFrames()
string[Math.min(f,a.length-1)]



This prints a single digit and sometimes a comma in AE. I'm not sure how to co-opt the code as it's an external JS file.


Return to posts index

Joe Richardson
Re: Updating Source Text's values from a JS file
on Feb 6, 2018 at 12:13:09 pm

I feel weird posting again, and I'm sorry if it's improper board etiquette, but...

Basically, I've got a CSV with 50 columns or so that get turned into 50 JS files. I used another of Dan Ebberts' scripts (http://www.motionscript.com/ae-scripting/create-text-layers-from-file.html) to create multiple text files and a solid from a TXT list.

I was wondering if it were possible to insert the corresponding Slider-Control effect and Source.Text expressions into each layer using the script.

This is my var text code:


var text;
while (!myFile.eof){
text = myFile.readln();
if (text == "") text = "\r" ;
myComp.layers.addText(text+".Value");
myComp.layers.addText(text+".Label");
myComp.layers.addSolid([1.0,1.0,0], text,50,50,1);


The way I have it set up is, I can do it manually once, for all 50(*3) layers and then save it as a template project since the Text-Label's never change. But I've been digging a lot, and I wanted to throw it out there before plunging in.

I've been trying to teach myself how to do this, but inserting relative paths, expressions, is way out of my league. Again, thanks.


Return to posts index


Joe Richardson
Re: Updating Source Text's values from a JS file
on Feb 7, 2018 at 1:36:01 pm

Well, I got really close to figuring out how to do everything in one script. I also couldn't figure out how to link to relative paths.

I just don't know how to write in the expressions in the same line as the layer in the script editor. Stuff like quotes, ";", and other things are very confusing. This is as far as I got:

var CSV_DataName_01;
myComp.layers.addText("CSV_DataName_01_Value").property("Text").property("Source Text").expression ="";
//var path = "D:\\Folder\\a.js";
//$.evalFile(path);
myComp.layers.addText("CSV_DataName_01_Label").property("Effects").addProperty("Slider Control").property("Slider").expression="";
//txt=thisComp.layer("CSV_DataName_01_Value").text.sourceText; if (! isNaN(parseFloat(txt))) parseFloat(txt) else value
myComp.layers.addSolid([1.0, 1.0, 0], "CSV_DataName_01", 50, 50, 1).property("Transform").property("Scale").expression ="";
//temp = thisComp.layer("CSV_DataName_01").effect("Slider Control")("Slider");
//[temp, 10]
//Also, I dont know how to add an effect in the same line after the expression: .property("Effects").addProperty("Transform")


Return to posts index

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