ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Reading internal source text.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Obed Ampong
Reading internal source text.
on Aug 15, 2018 at 5:16:53 pm

Hello,
I tried using the $.evalFile to locate source text external data and After Effects keep telling me " the file or the folder does not exist". So I tried to import the data manually by copying the data and removing read the path part of the expression. The modified expression is the second one however After Effects only read the individual characters of the comp name. Thus the modified expression resulted "C" instead of "Text 0" for (thisComp.name)[0] , "o" instead of "Text1" for(thisComp.name)[1] and "m" instead of "Text 2" for(thisComp.name)[2] .
Please, could someone kindly help me out?

Thanks in advance
Obed

myPath = "~C:/Users/Greatman/Documents/data/source.txt";
$.evalFile(myPath);
eval(thisComp.name)[0];


var comp1 = ["Text 0", "Text 1", "Text 2"];
(thisComp.name)[0];


Return to posts index

Dan Ebberts
Re: Reading internal source text.
on Aug 15, 2018 at 5:26:00 pm

If you put some legal JavaScript like this in your file:

txt = ["Text 0", "Text 1", "Text 2"];

Then you should be able to access the array elements of txt with an expression like this:

myPath = "/c/test/test.txt";
$.evalFile(myPath);
txt[0]

I'm not sure why you would want to get thisComp.name involved.


Dan



Return to posts index

Obed Ampong
Re: Reading internal source text.
on Aug 15, 2018 at 5:39:46 pm

Hi Dan,
thanks for the reply. I intended duplicating the comp for it to automatically change the text for the rest of the project because I have a lot of data to work with.

Obed


Return to posts index


Dan Ebberts
Re: Reading internal source text.
on Aug 15, 2018 at 6:13:13 pm

Then I guess you could do something like this:

myPath = "/c/test/test.txt";
$.evalFile(myPath);
idx = thisComp.name.substr(-1)-1;
txt[idx]


Dan



Return to posts index

Dan Ebberts
Re: Reading internal source text.
on Aug 15, 2018 at 6:18:57 pm

Wow, I'm surprised that worked. I meant to do it this way:

myPath = "/c/test/test.txt";
$.evalFile(myPath);
idx = parseInt(thisComp.name.substr(-1)-1,10);
txt[idx]


Dan



Return to posts index

Obed Ampong
Re: Reading internal source text.
on Aug 15, 2018 at 6:44:06 pm

I got an error: "file or folder does not exist" after using the file local address on the pc


Return to posts index


Dan Ebberts
Re: Reading internal source text.
on Aug 15, 2018 at 6:56:40 pm

Using your original path? Try it this way:

myPath = "/c/users/greatman/documents/data/source.txt";


Dan



Return to posts index

Obed Ampong
Re: Reading internal source text.
on Aug 15, 2018 at 7:13:03 pm

yea, I tried the path you suggested and the error was "unterminated string constant"
thanks

Obed


Return to posts index

Dan Ebberts
Re: Reading internal source text.
on Aug 15, 2018 at 8:17:07 pm

You can get that error if there's a problem with your text file (like a missing quotation mark).

By the way, if you have AE CC 2018, there are better ways to do this that don't involve the $.eval() hack.


Dan



Return to posts index


Obed Ampong
Re: Reading internal source text.
on Aug 15, 2018 at 10:10:26 pm

Yea, OK. that will be great. please, could you let me know?


Return to posts index

Dan Ebberts
Re: Reading internal source text.
on Aug 15, 2018 at 11:05:55 pm

OK, simple example. Say you have a comma-separated (CSV) file named "test.csv" like this:

1,2,3,4
Text 0,Text 1,Text 2,Text 3

(the first row is just the column headers--the data starts in the 2nd row)

You import that into your project. Then you could have a text expression like this:

idx = parseInt(thisComp.name.substr(-1)-1,10);
footage("test.csv").dataValue([idx,0])

which would pick the data corresponding the column identified by the last character in your comp name. Comp 1 gets Text 0, etc.

This won't work if you aren't using CC 2018.

Dan



Return to posts index

Obed Ampong
Re: Reading internal source text.
on Aug 16, 2018 at 12:16:45 pm

WOW, It worked!
Thank you so much!

Regards,

Obed


Return to posts index


Obed Ampong
Re: Reading internal source text.
on Aug 19, 2018 at 2:17:27 pm

Hi Dan,
Please, I have some issues with the expression for comp10, 20, 30, etc
It reads Data File: Either index or match name must be present, both are missing at path item 0....
Please, could you help me out?
Below is my data sample
comp1,comp2,comp3,comp4,comp5,comp6,comp7,comp8,comp9,comp10,comp11,comp12,comp13,comp14,comp15,comp16,comp17,comp18,comp19,comp20,comp21,comp22,comp23,comp24,comp25,comp26,comp27,comp28,comp29,comp30,comp31,comp32,comp33,comp34,comp35,comp36,comp37,comp38,comp39,comp40,comp41,comp42,comp43,comp44,comp45,comp46,comp47,comp48,comp49,comp50,......
1938,1939,1940,1941,1942,1943,1944,1945,1946,1947,1948,1949,1950,1951,1952,1953,1954,1955,1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988.......,

Thanks
Regards,
Obed


Return to posts index

Dan Ebberts
Re: Reading internal source text.
on Aug 19, 2018 at 3:01:27 pm

Try it this way:


idx = parseInt(thisComp.name.match(/\d+/),10)-1;
footage("test.csv").dataValue([idx,0])



Dan



Return to posts index

Obed Ampong
Re: Reading internal source text.
on Aug 19, 2018 at 3:50:30 pm

thanks, it worked.

regards,
Obed


Return to posts index

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