We're writing a bunch of .jsx scripts and in each I have to mock out some functions so I can use things like Array.map() and String.trim(), but I don't want to have to include that code at the top of every script.
Is there a way to "include" other .jsx scripts inside of a .jsx script file?
Just wanted to add a note to Ike10's answer. Undocumented is generous - this is the worst "documentation" I've ever come across in 20+ years of writing code. It seems to me that you must also add the CEFCommandLine argument to your manifest.xml file before the primary JSX file will load/eval external files:
We're now using the
$
helper available in Illustrator, and the$.evalFile()
method. Pass it a path and it will evaluate the file and return the result.I created a little helper that I can include (minified, of course) at the top of my .jsx scripts so I can do
Libraries.include("my-other-script")
that will include, in my case, a file that's in myadobe_scripts
root folder, in a directory calledlib
.Minified version that I include:
See gist here: https://gist.github.com/jasonrhodes/5286526
Or you can simply use
#include
and#includepath
preprocessor directives at the top of your script. You can find a detailed description in Adobe's "JavaScript Tools Guide".For example, if you want to include
scripts/helper.jsx
in a.jsx
file:Just leaving this here for anyone like me who is looking for this. In Adobe Illustrator CC 2015, I was unable to get
#include
to work, but@include
did. So for example:External File: foo.jsx
The Script File: bar.jsx
Disclaimer: I cannot find any documentation of this but have tested it with Adobe Illustrator CC 2015 and it works.
Hope this helps someone. If anyone has any questions just ask!