Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Passing info from JSX file to JS file

New Here ,
Dec 17, 2018 Dec 17, 2018

Hello,

I'm trying to create a custom panel for PPro. I know this is an After Effects Discussion, but my question seems relatively simple

and this forum is more active.

The script looks for a JSON file in the same location that the project file is saved in using extendscript. It then opens up that JSON file and

returns the data structure to a JS function. Everything works fine, besides the return line in JSX which returns 'undefined'

I've tried the following

return data

return JSON.stringify(data)

encodeURIComponent(JSON.stringify(data)) // I saw this in some examples of PPro Panels

There also seems to be a way to pass info back and forth with XML files, but I cannot figure out how to do that and

have failed to find good example code to follow.

// JSX Script

#include json2.jsx

$.readLyricFile = {

    readlyricsJSON: function() {

        try {      

            file = filePath(app.project.path) + '\\\\lyrics.json';

            data = jsonLoad(file);

        }

        catch(e) {

            data = 'Place Lyrics Here :)'

        }; 

   

    return encodeURIComponent(JSON.stringify(data));

}  

}

/** Load a data structure stored in a JSON file */

function jsonLoad(jsonFile) {

   var file = new File(jsonFile);

   var currentLine;

   var data = [];

   file.open('r');

  

   while (!file.eof) {

   currentLine = file.readln();

   data.push(currentLine);

  };

  

   file.close();

   data = data.join('');

  

   return JSON.parse(data);

};

// JS Script

/** if lyrics have been place in JSON file, reads JSON file */

function readLyrics() {

  cs = new CSInterface;                  

    data = cs.evalScript('$.readLyricFile.readlyricsJSON()'); // undefiened

    data = JSON.parse(data); // undefined

};

I appreciate any help. Thank You

TOPICS
Scripting
669
Translate
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

Community Expert , Dec 17, 2018 Dec 17, 2018

cs.evalScript

does not return a value.

If I remember correctly it needs a callback like this:

cs.evalScript('$.readLyricFile.readlyricsJSON()', function(result){

  alert("the jsx script returned the value"+result);

});

Translate
Community Expert ,
Dec 17, 2018 Dec 17, 2018
LATEST

cs.evalScript

does not return a value.

If I remember correctly it needs a callback like this:

cs.evalScript('$.readLyricFile.readlyricsJSON()', function(result){

  alert("the jsx script returned the value"+result);

});

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
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