Expression Tag - runScript

Hi,
I am trying to run a script placed inside the Project Library via an Expression Tag.

The script is as follows:

def  MyPath():
  
       ... example script ...

The Expression Tag is set as follows:

  • data Type: Float
  • execution mode: Fixed Rate
  • execution rate (ms): 5.000

The expression is as follows:

runScript( "MyPath()", 0 )

The tag result is: Error_ExpressionEval

I already tried to run the script in the Script Console and I get the right output value.

Suggestions?

Thanks to all.

Two main things I see:

  • runScript needs to reference the package/script file where your function is defined
  • The function should be called without parentheses

E.g. if MyPath is defined in file MyScriptFile, your expression would be:

runScript("MyScriptFile.MyPath", 0)

If there are still issues, I'd guess it's an error within the script itself.

Actually according to the docs: runScript | Ignition User Manual with parentheses is fine as a legacy.

What version of Ignition are you using?

1 Like

Use parenthesis when there are no arguments to pass. And then the full line of text will be executed.

Use no parenthesis when the line of text identifies a callable function, and there are arguments to pass included after the poll time argument.

The path of the script in the Project Library is:

Production/Dashboard

and the function definition is:

def production_1():

so the expression runScript is:

runScript( "Production.Dashboard.production_1()", 0 )

8.1.42

Is that script library in your gateway scripting project? Expression tags using runScript(), and any tags' event scripts, can only use scripts in the GSP. If that isn't configured, it simply won't work.

If you open the tag for editing in the designer, the tag diagnostics button (upper right) will probably give you more detail on that error.

2 Likes

I am sorry. What do you mean with "gateway scripting project"?

The diagnostic button give me this:

[null, Error_ExpressionEval("Error executing script for runScript() expresion: Production.Dashboard.production_1")]

Since tags aren't a project resource, a specific project must be identified as the gateway scripting project. See this portion of the manual: Project Library | Ignition User Manual

Then the tag will know how to get to the project library for the function that you are calling.

1 Like

Appreciate the info! I've always used the modern syntax, forgot legacy was an option.