FORUMS: list search recent posts

On the mystic faculty of reading an external plain text file.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Alberto Brancolini
On the mystic faculty of reading an external plain text file.
on May 18, 2017 at 10:54:41 pm

Hello everybody.

I browsed, I read, I executed... but I still can't successfully get AE reading an external file. I'm aware it's just about my ignorance, and yet I need help in some extent.
Attempts has been done both on a Mac and on a Windows, to no avail.
I always targeted only plain .txt files, also because that's exactly what the contingency is all about. Let's explain.

I'm working on a project that's being carried out both on Nuke and After Effects. Ok, that's simply nuts, but no more than life as a whole.
It takes to transfer tracking data from Nuke to After, and it turns out that the only way Nuke can dump tracking data but through fbx or some other evolute way, is by baking a plain ASCII file, formatted as such: two or three numbers per line, separated by spaces and returns only (no commas, no semicolons, no anything).
I managed to get the job done by copying the whole text and pasting into a text layer, for I can deal with data, once they are into AE. But I couldn't possibly get AE to read the file, straightaway.

I saw several tutorials and threads that demands a specific formatting of the text. I followed them. Nonetheless, I couldn't get the code working. All in all, I'm not gonna get any special formatting, nor I need it: as I told, spaces seem enough to get the work done through RegEx.

What I need, it is just a way to make AE read a .txt and feed everything into a variable (or the sourceText property of a text layer).

The code I write below (and associated to the sourceText parameter of a text layer), is the only one AE haven't scolded me for. It returned the caught error: "Reference Error: function $.eval is undefined". (And this is when I freak both hell and heaven out...)

I hope you can light my way. Thanks.

try {
myFile = "<i>absolute path to the file</i>";
$.eval(myFile);
eval(thisComp.layer("<i>the name I gave to the layer</i>").text.sourceText.value);
} catch(err) {
err;
}



Return to posts index

Dan Ebberts
Re: On the mystic faculty of reading an external plain text file.
on May 18, 2017 at 11:36:02 pm

Try
$.evalFile()

instaed of

$.eval()

Dan



Return to posts index

Alberto Brancolini
Re: On the mystic faculty of reading an external plain text file.
on May 19, 2017 at 8:10:08 am

Thank you Dan.

Now that I'm at the office, I tried as you suggested, at once. The situation changed.
This is the code I gave to the source text property of a text layer named Read:

try {
myFile = "C:\ALBERTO_LOCAL_SSD\tracker.txt";
$.evalFile(myFile);
eval(thisComp.layer("Read").text.sourceText.value);
} catch(err) {
err;
}

It tells me that the file does not exist.
As I saw in a tutorial by Harry Frank, Windows paths are not friendly as Mac's, hence I also tried to put \\ instead of \, as suggested. It tells me that expects a semicolon somewhere. I don't know where... and I think I'm just digging holes in the sand.

Just for completeness, this is how tracker.txt looks like (straight by Nuke):



Return to posts index


Dan Ebberts
Re: On the mystic faculty of reading an external plain text file.
on May 19, 2017 at 8:28:05 am

I'd use the platform-agnostic URI format for the path:

myFile = "/C/ALBERTO_LOCAL_SSD/tracker.txt";

The thing about this $.evalFile() hack though, is that the text has to be legal JavaScript. It might work if you edit your text file by adding triple quotes at the top and bottom:

"""
2044.0566410000 1925.1658940000
.
.
.
2041.1619870000 1856.905640000
""";

And change the read to something like this:

myText = $.evalFile(myFile);

Then do whatever you need to with myText.

Dan



Return to posts index

Alberto Brancolini
Re: On the mystic faculty of reading an external plain text file.
on May 19, 2017 at 9:42:49 am
Last Edited By Alberto Brancolini on May 19, 2017 at 9:56:05 am

Thanks you, Dan.
That worked a beauty!
Now these Nuke-dunk highbrows here at my office have their noses a little less in the air. 😜

May somebody find it useful, here is the full working code, applied to position:

myFile = "absolute path to the file";
data = $.evalFile(myFile);
a = data.match(/[d.]+/g); this RegEx reads every digit included into the string, it takes on each space and return as a separator, and creates an array
w = timeToFrames(time)*2; or 3, if Z data are included
x = a[w];
y = thisComp.height-a[w+1]; because Y coordinates in Nuke are flipped
z = a[w+2]; only if Z data are included
[x,y,z];


Return to posts index

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