如何在罗勒.js中包含其他脚本

How to include additional scripts in basil.js

本文关键字:包含 其他 脚本 js 罗勒      更新时间:2023-09-26

Basil.js的新手,但非常喜欢它。

我想知道是否可以在我的 .jsx 脚本中链接其他 javascript 工作表以及正确的过程是什么。当我尝试时:

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

InDesign 抛出错误:

错误号:48冒犯性文本:#include"basiljs/users/anotherscript.jsx";

是的,您可以正常包含:)例如,下面的示例展示了如何在罗勒草图中包含下划线.js。请注意第一行带有"#includepath",这一行基本上包括Mac和PC的整个文档文件夹...然后,您可以从那里指定要包含的文件的相对路径。

#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();

我认为你不能在扩展脚本中使用这种方式包含。

但是这将起作用:

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

如果它不起作用,请尝试脚本的完整路径。

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