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

Use external js file in JSX?

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

TOPICS
Scripting

Views

1.8K

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

Valorous Hero , Aug 04, 2020 Aug 04, 2020

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.

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 04, 2020 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?

Votes

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
Valorous Hero ,
Aug 04, 2020 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.

Votes

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

Votes

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
New Here ,
Aug 01, 2022 Aug 01, 2022

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.

Votes

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 ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

@keerthana24466750osmu 

Did you include your js file in jsx?
Could you please post your code?

 

Best regards

Votes

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
New Here ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

LATEST

@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

Votes

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