Highlighted

Use external js file in JSX?

Participant ,
Aug 04, 2020

Copy link to clipboard

Copied

From a js file to fire up a JSX file that communicates with illustrator I do this:

 

 

var productTemplateSetupFile = `${root}/jsx/productTemplateSetup.jsx`;  
csiRun.evalScript(`$.evalFile('${productTemplateSetupFile}')`);
csiRun.evalScript(`setupPlateTemplate('${jsonOrders}')`);

 

Here I eval the file then eval the method setupPlateTemplates(); and it executes.

 

Is there away that I could run other JS files in this jsx?

I've read mixed reviews on this and nothing has helped.

In example:

#include (anotherJsFile.js);
function setupPlateTemplate(orders) {
   myMethodInAnotherJsFile();
}

The method would include a bunch of other code that can run with some node modules.  I'm not sure if this is possible.

Adobe Community Professional
Correct answer by Silly-V | Adobe Community Professional

In extendscript, node modules will probably not run unless they are first turned into ES3-style ancient javascript.
But to include another file inside a JSX script would be possible via:
eval("#include '/Path/Script.jsx'");

So you can pass in names & locations of separate JSX files from the js side, then use the code inside to interact with your variables just like in your example.

TOPICS
Scripting

Views

65

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

Use external js file in JSX?

Participant ,
Aug 04, 2020

Copy link to clipboard

Copied

From a js file to fire up a JSX file that communicates with illustrator I do this:

 

 

var productTemplateSetupFile = `${root}/jsx/productTemplateSetup.jsx`;  
csiRun.evalScript(`$.evalFile('${productTemplateSetupFile}')`);
csiRun.evalScript(`setupPlateTemplate('${jsonOrders}')`);

 

Here I eval the file then eval the method setupPlateTemplates(); and it executes.

 

Is there away that I could run other JS files in this jsx?

I've read mixed reviews on this and nothing has helped.

In example:

#include (anotherJsFile.js);
function setupPlateTemplate(orders) {
   myMethodInAnotherJsFile();
}

The method would include a bunch of other code that can run with some node modules.  I'm not sure if this is possible.

Adobe Community Professional
Correct answer by Silly-V | Adobe Community Professional

In extendscript, node modules will probably not run unless they are first turned into ES3-style ancient javascript.
But to include another file inside a JSX script would be possible via:
eval("#include '/Path/Script.jsx'");

So you can pass in names & locations of separate JSX files from the js side, then use the code inside to interact with your variables just like in your example.

TOPICS
Scripting

Views

66

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
Aug 04, 2020 0
Contributor ,
Aug 04, 2020

Copy link to clipboard

Copied

I don't think it's possible the way you would like.

 

However, is there any scope for restructuring your script to have all the js logic happening on the js side, even if it means lots of calls to functions on the jsx side?

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
Reply
Loading...
Aug 04, 2020 0
Adobe Community Professional ,
Aug 04, 2020

Copy link to clipboard

Copied

In extendscript, node modules will probably not run unless they are first turned into ES3-style ancient javascript.
But to include another file inside a JSX script would be possible via:
eval("#include '/Path/Script.jsx'");

So you can pass in names & locations of separate JSX files from the js side, then use the code inside to interact with your variables just like in your example.

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
Reply
Loading...
Aug 04, 2020 0
Adobe Community Professional ,
Aug 04, 2020

Copy link to clipboard

Copied

Hello,

I think this is possible if you know your path of your js file. I have tried following. I have two files named as sample.jsx and sample.js stored at my desktop

 

sample.js code

function callMethodInJS() {
    alert("I am in JS");
}

 

sample.jsx code

$.evalFile(File('~/Desktop/sample.js'));

function test(){
    callMethodInJS();
}

test();

 

I have not exceuted these filed using CEP panels. But when I executed sample.jsx file from Extended toolkit. It shows an alert message which is in js file. If it able to execute like this, then it should definitely be done by CEP panels as well. Just make sure to give correct path of js file in jsx file while evaluating it.

 

Let us know if this helps in your work flow.

Best regards

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
Reply
Loading...
Aug 04, 2020 2