Tot*_*.js 8 javascript adobe require include adobe-indesign
如何加载另一个脚本文件并在其上运行方法?
我正在使用InDesign javascript,我不知道如何在同一个脚本中包含多个文件.
dln*_*385 10
三个选项:import,app.doScript和$ .evalFile.我更喜欢$ .evalFile.请参阅app.doScript vs $ .evalFile
C:\ script1.jsx
(function() {
$.evalFile(new File("/c/script2.jsx"));
var sFullName = g_script2.combineName("John", "Doe");
$.writeln(sFullName);
return "Success";
})();
Run Code Online (Sandbox Code Playgroud)
C:\ script2.jsx
g_script2 = {
combineName: function(sFirstName, sLastName) {
return sFirstName + " " + sLastName;
}
};
Run Code Online (Sandbox Code Playgroud)
如果script2.jsx不在C驱动器的根目录中,请使用其真实位置修改脚本1.
sFullName
将是全球性的.g_script2
.combineName
脚本2 的方法.重要的是要注意脚本的所有文件将共享相同的全局命名空间,这是脚本1可以访问的方式g_script2
.但是,这也意味着没有两个文件应该具有相同的函数或变量名称,除非它们保存在像这个示例中的全局对象中.combineName
函数运行,并返回一个字符串.ExtendScript 提供用于包含外部脚本的预处理器指令。\n该指令将目标文件的内容插入到当前脚本文件的语句位置。因此,在该语句之后,您将能够调用任何类似它的方法\xe2\x80\x99s当前脚本的方法:
\n\n#target InDesign; \n\n// Include other script file that includes a function otherScriptFileMethod\n#include "otherScriptFile.jsx"\n\n// Now you can call the method as it was written in this script file\notherScriptFileMethod();\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
3297 次 |
最近记录: |