Highlighted

Is it possible to reference another js file in an illustrator script?

Explorer ,
Jul 10, 2020

Copy link to clipboard

Copied

I have a JS script that selects layers and another one that moves items to a named layer.

var aDoc = app.activeDocument;
var layerName1 = 'Background';
aDoc.activeLayer = aDoc.layers.getByName(layerName1);

I want to be able to define all the Layer Names in another file and reference it into the above file and its ilk.

But I have tried to reference the file but I get errors.

The idea is to apply a shortcut to each scripts and program it to my keyboard.

Any help on this?

Adobe Community Professional
Correct answer by Charu Rajput | Adobe Community Professional

You can include one script in other script using 

#include "sample.jsx"

 

sample.jsx - will be complete path of your script.

 

Let us know if you need more help.

TOPICS
Scripting

Views

68

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

Is it possible to reference another js file in an illustrator script?

Explorer ,
Jul 10, 2020

Copy link to clipboard

Copied

I have a JS script that selects layers and another one that moves items to a named layer.

var aDoc = app.activeDocument;
var layerName1 = 'Background';
aDoc.activeLayer = aDoc.layers.getByName(layerName1);

I want to be able to define all the Layer Names in another file and reference it into the above file and its ilk.

But I have tried to reference the file but I get errors.

The idea is to apply a shortcut to each scripts and program it to my keyboard.

Any help on this?

Adobe Community Professional
Correct answer by Charu Rajput | Adobe Community Professional

You can include one script in other script using 

#include "sample.jsx"

 

sample.jsx - will be complete path of your script.

 

Let us know if you need more help.

TOPICS
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
Jul 10, 2020 0
Adobe Community Professional ,
Jul 10, 2020

Copy link to clipboard

Copied

You can include one script in other script using 

#include "sample.jsx"

 

sample.jsx - will be complete path of your script.

 

Let us know if you need more help.

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...
Jul 10, 2020 0
Explorer ,
Jul 10, 2020

Copy link to clipboard

Copied

I have always used the extension .jsxinc in the include e.g #inlcude layers.jsxinc. I am assuming based of this it is not a requirement?

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...
Jul 10, 2020 0
m1b LATEST
Contributor ,
Jul 10, 2020

Copy link to clipboard

Copied

Also note, if you are using Visual Studio Code and ExtendScript Debugger, you need "//@include", eg.

//@include "../lib/otherFile.js"

 

I don't think it matters which extension you use. I've not had trouble with .js and .jsx anyway. Using .jsxinc just seemed unnecessary so I gave it up.

 

Mark

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...
Jul 10, 2020 1