Chapter 3. Scripting

Executing Algorithms in Rocs

Rocs internally uses the QtScript JavaScript engine. This means, all algorithms that you implement must use JavaScript. In the following, we explain how to access and change elements of a graph document from the scripting engine. It is important to note that changes done by the scripting engine are directly reflected at the properties at the graph editor elements.

Control Script Execution

There are different execution modes for your algorithms:

  • Run: Execute the script until it finishes.

  • Stop: Stop script execution (only available while a script is executed).

Script Output

During the execution of an algorithm, debug and program output is displayed in the Debug & Script Output. If the scripting engine detects a syntax error in your script, the error is also displayed as debug message. Note that all program messages are also displayed at the debug output (displayed as bold text).

You can control the text that is displayed at the script output by the following functions:

    Console.log(string message);            // displays the message as script output
    Console.debug(string message);          // displays the message as debug output
    Console.error(string message);          // displays the message as error output

Scripting Engine API

The different parts of Rocs each provide a static element that can be accessed by the scripting engine. These are:

  • Document for the graph document

  • Console for the console log output

For the explicit API use and for a method reference, please see the inline help at the Rocs side bar.