The following elements are defined in the global scope by default and accessible to all scripts.
alert
{Function} - Shows an alert box with arbitrary message. An alert box can be used if you want to make sure information comes through to the user. However, an alert box is modal so should be used with care since it blocks the further execution of the script until the user has confirmed with "OK". Not available in all languages. Or more precisely: only available in Java Script as concession to Java Script developers.
// show some result to the user alert("Hello World");
Stability 3 - Stable
console
{Object} - Used to log formatted messages and errors to the script console. See Console section. To see the output, the Console view has to be opened. Not available in all languages. Again, only available in Java Script as concession to Java Script developers.
// log a message and a formatted error message var any = ... console.log(any); console.error("Object {0} is of type {1}", any, typeof any);
Stability 3 - Stable
finder
{Object} - A pre-defined Finder instance. The finder is bound to the current project, i.e. the project, the script is executed against. See the Finder section for a full API description.
// find objects with a given name in the project finder.find("name", "Item Definition");
Stability 3 - Stable
__filename
{String} - The filename of the code being executed. This is the name of the script code file beeing executed. Not available in all scripting languages.
console.log(__filename); // e.g. example.js
Stability 2 - Unstable
__filepath
{String} - The filepath of the code being executed. This is the resolved absolute path of this code file using the platform-dependent path separator. Not available in all scripting languages.
console.log(__filepath); // e.g. C:\Users\...\scripts\example.js
Stability 2 - Unstable
__filedir
{String} - The directory of the script file being executed. This is the resolved absolute path of this directory using the platform-dependent path separator. Not available in all scripting languages.
console.log(__filedir); // e.g. C:\Users\...\scripts
Stability 2 - Unstable
__tool_version
{String} - The version of the tool including major and minor versions as well as patch level and build number and as shown in the about dialog. Not available in all scripting languages.
console.log(__tool_version); // e.g. 3.4.0.12345
Stability 2 - Unstable
__tool_version_number
{Number} - The version of the tool as a number build from the major, minor and patch level version, i.e. 3.4.0.12345 will result in 340. Not available in all scripting languages.
if (__tool_version_number >= 340) console.log("yes, we have 3.4.0");
Stability 0 - Deprecated since 21.2.0 - use __tool_version or __tool_version_object instead
__tool_version_object
{Object} - The version of the tool as an object supporting major, minor and micro version as numbers and an optional qualifier as a string. Not available in all scripting languages. Note: this was newly introduced with 21.1.0 and replaces __tool_version_number.
if (__tool_version_object.major >= 3 && __tool_version_object.minor >= 4) { console.log("yes, we have at least 3.4.0"); }
Stability 2 - Unstable
load()
{Function} - Offers a very simple module loading mechanism. Accepts a script as the first argument. Scripts can be either loaded relative to the currently executed script, or using an absolute pathname, or using an URL to an external file. To prevent name collisions, the optional second argument accepts a JavaScript object and uses it as the scope for the load.
Not available in all scripting languages.
// load sibling load("mylib.js"); // load script from server load("http://scripting.org/famous-script.js", scriptScope);
Stability 3 - Stable
progressMonitor
{Object} - Can be used to monitor the progress of a script; useful especially for long running operations. All activity is broken down into a linear sequence of tasks against which progress is reported. The object implements the IProgressMonitor interface. Not available in all scripting languages.
progressMonitor.beginTask("Test", 100); for (var i = 0; i<100; i++) { // TODO do something progressMonitor.worked(1); } progressMonitor.done();
Stability 3 - Stable
selection
{Array} - In case a script is executed on a set of selected element, the
selectioncontains the list of elements. Otherwise the variable is defined but the array is empty. Not available in all scripting languages.
// Show the user some infos about the selection if (!selection) { "No selection."; } else if (selection.length == 0) { "Empty selection."; } else { "You have " + selection.length + " item(s) selected."; }
Stability 3 - Stable
prompt
{Function} - Displays a dialog box that prompts the user for input. The user will have to click either "OK" or "Cancel" to proceed after entering an input value. The message argument and the default input argument are mandatory. The prompt() method returns the input value if the user clicks "OK". If the user clicks "cancel" the method returns null. Only available in Java Script as concession to Java Script developers.
// Request some user data var name = prompt("Give me your name", "John Doe"); if (name) { alert("Hello " + name); }
Stability 3 - Stable
confirm
{Function} - Displays a dialog box with a specified message, along with an OK and a Cancel button, often used if you want the user to verify or accept something. The message argument is mandatory. The confirm() method returns true if the user clicked "OK", and false otherwise. Only available in Java Script as concession to Java Script developers.
// Confirm some user data if (confirm("Are you really John Doe?")) { alert("Hello John!"); } else { alert("Oops, sorry."); }
Stability 3 - Stable
parseBigDecimal
{Function} - Parses an argument (converting it to a string first if needed) and returns a BigDecimal object. Leading and trailing spaces are allowed. If the argument cannot be converted to a BigDecimal, it returns NaN. Only available in Java Script complementary to parseFloat and parseInt.
var a = parseBigDecimal(" 2.5432 "); a = a.pow(parseBigDecimal(10));
Stability 3 - Stable