Importing And Exporting Between Scripts - Adobe 27510753 - InDesign CS2 - PC Manual

Scripting guide
Hide thumbs Also See for 27510753 - InDesign CS2 - PC:
Table of Contents

Advertisement

Adobe InDesign CS2 Scripting Guide
#script name
#strict on
#target name

Importing and exporting between scripts

The ExtendScript JavaScript language has been extended to support function calls and variable access across
various source code modules and ExtendScript engines. A script can use the export statement to make its
definitions available to other scripts, which use the import statement to access those definitions.
To use this feature, the exporting script must name its ExtendScript engine using the #engine preprocessor
statement. The name must follow JavaScript naming syntax; it cannot be an expression.
For example, the following script could serve as a library or resource file. It defines and exports a constant and
a function:
#engine library
export random, libVersion;
const libVersion = "Library 1.0";
function random (max) {
return Math.floor (Math.random() * max);
}
A script running in a different engine can import the exported elements. The import statement identifies the
resource script that exported the variables using the engine name:
import library.random, library.libVersion;
print (random (100));
You can use the asterisk wildcard ( * ) to import all symbols exported by a library:
import library.*
Objects cannot be transferred between engines. You cannot retrieve or store objects, and you cannot call
functions with objects as arguments. However, you can use the JavaScript toSource function to serialize
objects into strings before passing them. You can then use the JavaScript eval function to reconstruct the
object from the string.
For example, this function takes as its argument a serialized string and constructs an object from it:
function myFn (serialized) {
var obj = eval (serialized);
// continue working...
}
Names a script. Enclosing quotes are optional, but required for names that include
spaces or special characters. For example:
#script SetupPalette
#script "Load image file"
The name value is displayed in the Toolkit Editor tab. An unnamed script is assigned
a unique name generated from a number.
Turns on strict error checking. See the Dollar ($) Object's strict property.
Defines the target application of this JSX file. The name value is an application
specifier; see the "Application and Namespace Specifiers" section. Enclosing quotes
are optional.
If the Toolkit is registered as the handler for files with the . jsx extension (as it is
by default), opening the file opens the target application to run the script. If this
directive is not present, the Toolkit loads and displays the script. A user can open a
file by double-clicking it in a file browser, and a script can open a file using a File
object's execute method.
Using ExtendScript Tools and Features
71

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs2

Table of Contents