This function is used by Ignition's Expression language.
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 a entered as a string and the pollRate is in milliseconds. You can optionally add any function arguments after the poll rate.
runScript(scriptFunction[, pollRate][, args...])
string scriptFunction - A single line of python code. Typically the path to a script module.
int pollRate - Optional. The poll rate of the script.
object args - Optional. Any number of argument objects that will be passed into the given script.
object - The return value of the specified function.
Here is our scripting function we are going to run that is located in a shared script called textScript.
def myFunc(text="Hello World!"):
return text
// run a shared function with this expression
runScript("shared.textScript.myFunc()", 0) //This would run the script and return "Hello World!".
// run a shared function dynamically with this expression
// using string concatenation. A poll rate is unnecessary, as it will refresh when the tag value changes.
runScript("shared.textScript.myFunc('" +{_gensim_/Writeable/WriteableString1} + "')", 0) // This would run the function and pass in the value of the WriteableString1 tag.
// run a shared function dynamically with this expression
// using optional arguments. A poll rate is unnecessary, as it will refresh when the tag value changes.
// Note the missing "()" at the end of the scriptFunction string
runScript("shared.textScript.myFunc", 0, {_gensim_/Writeable/WriteableString1})
4 Comments
Anonymous
Can an example be provided for runScript with arguments?
Anonymous
Here is an example, where the root container has a custom function called "calculateAggregates(dataset)":
runScript("self.calculateAggregates", 0, {Root Container.MyDataSet})
Anonymous
What are the units of poll rate? msecs?
Robert McKenzie
Yes!