Skip to main content
Version: 8.1

runScript

This function is used by Ignition's Expression language.

Description​

Runs a single line of Python code as an expression. If a poll rate is specified, the function will be run repeatedly at the poll rate. This is a very powerful way for you to add extensions to the expression language. For example, one could write a project script module function called shared.weather.getTempAt(zip) that queried a web service for the current temperature at a given zipcode, and then bind the value of a label to the return value of that function.

The scriptFunction is entered as a string and the pollRate is in milliseconds. You can optionally add any function arguments after the poll rate.

note

Normally expressions execute fairly quickly when compared to a script. However, calling runScript will mitigate the speed advantage of an expression. In most cases this is unnoticeable, but calling long running scripts with runScript can negatively impact performance.

Calling runScript in Tags​

The runScript function can be used in expression tags, but the poll rate doesn't work exactly the same as in an expression binding. All Tags have a Scan Class that dictates the minimum amount of time between each evaluation. The runScript poll rate only polls up to the rate of the scan class set on the tag.

For example, if an Expression Tag is configured with runScript to run at a poll rate of 60 seconds and is using the "default" (1 second) scan class, the Tag's Expression will still execute every 1 second. So a scan class rate of 60 seconds will be necessary for a runScript expression to poll at any rate between 0 and 60 seconds.

Syntax - Preferred​

runScript(scriptFunction, [pollRate],[arg1],[arg2],[arg...])

  • Parameters

    • String scriptFunction - A single line of python code. Typically the path to a script module.

    • Integer pollRate - The poll rate of the script in milliseconds. [optional]

    • Object arg - Any number of argument objects that will be passed into the given script. This expression function can't make use of keyword invocation, so the order of the arguments passed to runScript represents how the parameters will be passed to the underlying Python function. [optional]

  • Results

    • Object - The return value of the specified function.

Syntax - Legacy​

runScript(scriptFunction, [pollRate])

  • Parameters

    • String scriptFunction - A string representing a single line of code, including any arguments that will be passed to the function.

    • Integer pollRate - The poll rate of the script in milliseconds. [optional]

  • Results

    • Object - The return value of the specified function.

Examples​

Here is our scripting function we are going to run that is located in a Project Library script called textScript. The project the script was in was also set as the Gateway Scripting Project.

Code Snippet - Python Function
def myFunc(text="Hello World!", moreText="Good bye"):
return text
General Usage
// This code block shows how to use runScript without additional parameters.

// Preferred syntax.
runScript("textScript.myFunc")

// Legacy syntax.
runScript("textScript.myFunc()")
Passing Arguments
// Preferred syntax.
runScript("textScript.myFunc", 0, "Hello Again", "See ya later")

// Legacy syntax.
runScript("textScript.myFunc('Hello Again', 'See ya later')", 0)
Example - Legacy Usage
// Legacy syntax using string concatenation.
runScript("textScript.myFunc('" +{_gensim_/Writeable/WriteableString1} + "')") // This would run the function and pass in the value of the WriteableString1 tag.