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.
1 Correct answer
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.
Explore related tutorials & articles
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?
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.
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.
Copy link to clipboard
Copied
Hi Team,
I am trying to use the js file inside jsx file.
I tried using the above sample method, but facing the below error
Error 21: undefined is not an object. Line: 1 -> $._ext_ILST.getCurDocumentPath()
Any help would be great.
Thanks in advance.
Copy link to clipboard
Copied
Did you include your js file in jsx?
Could you please post your code?
Copy link to clipboard
Copied
@Charu Rajput
Yeah, I tried to include js to my jsx file.
I have attached the js file and jsx file as well.
Structure will be something like
com.mpm.extension
Client -> CEPMPUTIL.js
Host ->main.jsx
Let me know if any more info required or can we connect over a call also if needed.
Thanks

