AE Scripting: file.exists, file.open, file.close is undefined

Explorer ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

Hi,

I have an automation script that reads from a json file to do various things.  For months, the utility function which reads the json file has worked perfectly.  Suddenly today, it's causing an error that

"file.exists is undefined", same for file.open() and file.close()
What the hell is going on?  It's prbably something stupidly simple but I can't solve it. 

var jsonfile= File("X:/some/path/this.json");
jsondata = readJson(jsonfile)


function readJson(file){

  if (file.exists()){
    file.close() //if left open
    file.open("r");
    while(!file.eof){
      line = file.readln() ;
      data.push(line) ;
      data = data.join("") ;
      var parsedData = JSON.parse(data);
      return parsedData ;
    }
    file.close();
  }

}

TOPICS
Error or problem , How to , Scripting

Views

69

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jul 28, 2022 Jul 28, 2022

to be more specific:

aep = thisArray[1]
alert (aep)

>>"X:/some/path/project.aep"

aep_file = File(aep);
alert(aep_file);
>> "/x/some/other/path/X:/some/path/project.aep"

On the other hand, if i explicity cast the variable

to be more specific:

aep = "X:/some/path/project.aep"
alert (aep)

>>"X:/some/path/project.aep"

aep_file = File(aep);
alert(aep_file);
>> "/x/some/path/project.aep"

And the problems continue...
startframe = thisArray[2] //value ="1001", type string
alert(startframe)
>>1001
startframe = parseInt(thi

...

Likes

Translate

Translate
Explorer ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

Nevermind. 
I got rid of the file check:  file.exists()  and it seems to be working again. 

Kinda dumb. 
Was AE scripting intentionally designed to be difficult and counterintuitive?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

file.exists is a property, not a method, so I would expect file.exists() to cause problems.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

Here's a new one...

var aep = 'X:/some/path/project.aep';
alert(aep);

//alerts "X:/some/path/project.aep"

aep_file = File(aep);
alert(aep_file);
//alerts "X:/some/other/path/X:/some/path/project.aep"

app.ope(aep_file)
Error: "...path is not valid"
No sh-t.  Why is it adding an additional path when I've explicity told it what the path is?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

This works perfectly for me:

var aep = '/c/test/project.aep';
var aep_file = File(aep);
app.open(aep_file);

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

to be more specific:

aep = thisArray[1]
alert (aep)

>>"X:/some/path/project.aep"

aep_file = File(aep);
alert(aep_file);
>> "/x/some/other/path/X:/some/path/project.aep"

On the other hand, if i explicity cast the variable

to be more specific:

aep = "X:/some/path/project.aep"
alert (aep)

>>"X:/some/path/project.aep"

aep_file = File(aep);
alert(aep_file);
>> "/x/some/path/project.aep"

And the problems continue...
startframe = thisArray[2] //value ="1001", type string
alert(startframe)
>>1001
startframe = parseInt(thisArray[2]) //value ="1001", type string
alert(startframe)
>>NaN

This is infuriatingly difficult.  I need to run a batch process that opens up spcific project files, edits comps and layer properties, and then moves on to the next one.  But I'm stuck on parsing data types which seems to be forbidden knowledge.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

LATEST

errors were a result of reading from a text file where the array values were pre-loaded with quotation marks.
because the text file was formatted like this:
shotName = "['filename','aep','startframe',...]"
instead of this:
shotName = "[filename,aep,startframe,...]"

 

this meant that the array value was being read as:
thisArray[1] = ""x/some/path/filename.aep""

be careful how you format text for batch file implementation

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

Make your promotional social content with Adobe Express.

Get started quickly with free templates: