LogixNG Reference - Chapter 13

Jython Scripting Support

Jython is an important component provided by JMRI to make it possible to extend the JMRI features. LogixNG continues that ability to run scripts supporting JMRI using the same actions that were part of the original Logix. LogixNG extents that support to include the ability to extend LogixNG itself, provide access to the LogixNG managers, provide access to global variables and receiving results from a script, etc.

The following is a summary of the scripting options.

The LogixNG includes additional bindings to support LogixNG access.

These work like the standard bindings, such as masts.getSignalMast('mastName'). For example: myTable = logixngTables.getNamedTable('tableName').


Sample script for accessing LogixNG content

A global variable is defined using Tools ⇒ Tables ⇒ LogixNG ⇒ LogixNG Global Variables with an initial value of Hello. The script is called using a Script action. The Log local variables action is called before and after the script.

The script gets access to the global variable and modifies the value.

import java
import jmri

var = globalVariables.getGlobalVariable('first_prog')
phrase = '{} World'.format(var.getValue())
var.setValue(phrase)
        

The before and after global value shows the change.

WARN  - Log local variables: [JMRI LogixNGThread]
WARN  - Global variables: [JMRI LogixNGThread]
WARN  -     Global Name: first_prog, value: Hello [JMRI LogixNGThread]
WARN  - Log local variables done [JMRI LogixNGThread]
WARN  - Log local variables: [JMRI LogixNGThread]
WARN  - Global variables: [JMRI LogixNGThread]
WARN  -     Global Name: first_prog, value: Hello World [JMRI LogixNGThread]
WARN  - Log local variables done [JMRI LogixNGThread]
        

Return to the Reference TOC