The following will explain the power of ROB-EX Scripting by showing how a simple script is created and executed.

Overview

The Scripting option allows the full ROB-EX API to be called and manipulated through the Groovy Scripting language (see ). The Groovy language is a powerful and easy to use scripting language supporting both all standard Java features as well as unique power features well suited for scripting.

Scripting in ROB-EX Includes

  • an online Scripting console (menu “Functions->Script Console”) with syntax highlighting for development and evaluation of scripts, i.e. write a script on the fly and evaluate it without restarting ROB-EX
  • a macro command ExecuteScript that will allow a script to be executed in a normal macro
  • the ability to automatically load and execute scripts during startup of the client

Scripting in ROB-EX requires a valid license for the ROB-EX API Developers Kit. With a valid license the menu “Functions->Script console” is enabled.

A small tutorial

Selecting menu item “Functions->Script console” will open up the GroovyConsole.

With a ROB-EX test plan loaded into the client (for testing it is recommended to logout from a possible Multiuser server) try to copy/paste the following code into the script console (the upper part of the GroovyConsole window).

import org.joda.time.DateTime;
import gantt.plugin.BaseModelAPI;

print "Hello World!"

def bAPI = pluginAPI.getBaseModelAPI()

// find all operations with start before now and update their start date to NOW

bAPI.getOperationList().findAll{o -> o.getStart().isBeforeNow() && o.type==-2 && o.getProductionOrder() != null && o.getResource() != null}
  .each{o -> o.setStart(new DateTime())}

Except for the import statements in the top, this script only consists of a single line that iterates through all operations starting before now and which has a type of -2. For each of these operations the current start time is set to the current date and time.

The variable pluginAPI is a variable that is passed into the script from the ROB-EX client, i.e. it is always there without it having to be defined anywhere. The pluginAPI variable is of type gantt.plugin.PluginAPI, and will allow the script to query and manage basically any part of the ROB-EX client.

Before executing the script press the “View” menu and use the following recommended settings:

To run the script select menu “Script->Run” or press Ctrl+R as a shortcut. The result in your ROB-EX plan is that all operations in the plan that previously had a starting date prior to NOW, starts at time NOW.

It is best practice to place groovy scripts in the “custom” directory, alongside with other customer specific configurations.

Automatically loading scripts during client startup

From ROB-EX 4.2 and forward scripts can be automatically loaded and executed once, which is useful for scripts that register themselves as call back listeners (i.e. you need to ensure that they will only register a single call back listener). A script is automatically loaded when they are placed in the following directory of the client.

<sch_dir>\custom\scripts\beforePlugins

Groovy script files placed in this directory will be loaded and executed before the user plugin is loaded. Scripts are loaded in alphabetical order, so use a naming convention like “01_script.groovy”, “02_script.groovy” etc. to control in which order scripts are loaded.
This option is useful in case the script configures or initializes resources that the user plugin depends on (as an example a connection to a database or some other data source).

<sch_dir>\custom\scripts\afterPlugins

Groovy script files placed in this directory will be loaded and executed after the user plugin has been loaded and initialized but before the plan has been loaded. Scripts are loaded in alphabetical order, so use a naming convention like “01_script.groovy”, “02_script.groovy” etc. to control in which order scripts are loaded.
This option is useful for situations where the script depends on some initialization having taken place in a user plugin.

To see an example of a script being loaded during startup see the “Oven Scheduling” example in <sch_dir>\data\scripts\scheduling\ovenScheduling. This script demonstrates both how to create a macro from a script loaded during startup and it also shows how to override the standard scheduling rules in order to support scheduling of oven type resources.

Scripting examples

A number of scripting examples demonstrating how to use scripting for data cleanup, interfacing via SQL, Excel etc. are included as part of the standard Client installation. The examples are available in the <sch_client_dir>\data\scripts directory.

Feedback

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.

Post your comment on this topic.

Post Comment