How to include additional scripts in basil.js

403 Views Asked by At

New to Basil.js, but love it dearly.

I am wondering if it is possible to link other javascript sheets in my .jsx script and what the correct procedure is. When I try:

#include "basiljs/users/anotherscript.jsx";

InDesign throws err:

Error Number: 48 Offending Text: #include "basiljs/users/anotherscript.jsx";

2

There are 2 best solutions below

0
On

I don't think you can use include that way in extendscript.

However this WILL work:

//include another script
$.evalFile(new File("basiljs/users/anotherscript.jsx"));

If it doesn't work, try a full path to your script.

$.evalFile(new File("/c/somefolder/basiljs/users/anotherscript.jsx"));
0
On

yes you can normal includes :) the example below shows for instance how to include underscore.js to your basil sketch. please note the very first line with "#includepath", this line basically includes the whole document folder for mac and pc ... then you can specify from there on a relative path to the file for including.

#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";
#include "basiljs/libraries/underscore.js";

function draw() {
  var result = _.map([1, 2, 3], function(num){ return num * 3; });
  b.println( result );
}

b.go();