Setting component Properties in a Startup Script

Hi all,

We have a large number of valves on our system, around 100 each of two different types. For continuity with an old HMI package, we would like to present them as a list of 20 valves per window, in a tabular format. For reasons of continuity, we have a ‘home’ page with several buttons, that open up different projects using the system.util.retarget function.

A Memory Tag, dataset format, holds all the relevant data about each valve. The template repeater’s Template Parameters dataset property, is linked to the master memory tag dataset via a runScript expression function. I couldn’t find a cleaner way to have a dataset template pull a subset of a larger dataset.

Each window has a custom property called ‘page’ which the runScript expression uses to select the subsection of the Memory Tag’s data set - 0-19, 20-39, 40-59, and so on. Each subset currently has its own window in the project.

Once the project is open, navigating among different windows is redundant. You could simply have the button re-write the template repeater’s dataset. But the chicken/egg issue is that before the project is open, you need to know which subset is wanted.

System.util.retarget has a ‘params’ function:
PyDictionary params - A dictionary of parameters that will be passed to the new project. They will be set as global variables in the new project’s Python scripting environment. [optional]

But I have been unable to figure out how to use this global variable. If a client startup script could reference a global variable, write the template repeaters Template Parameters we’d be off to the races and could cut ourselves down from 4-5 pages to a single one. Is this possible and if so how?

When you say you haven’t found a way to use the global variables: Are you using the getGlobals() function? system.util.getGlobals - Ignition User Manual 8.1 - Ignition Documentation

If not, then odds are you need to use that specific function to access the parameters you are passing.

It was my understanding that with a global declared in python, nothing further is required to use it, regardless of scope.

I.e. system.util.retarget(NewProject, params ={‘testval’:1.0})

and then a client script that is something like
def main():
return testval == 1.0
main()

Should simply return True, no? If this is not the case, I’ll checkout getGlobals.

The Global namespace in Ignition is not the same as python global variables. The retarget() function is specifically updating the Ignition global namespace which can be accessed with getGlobals().

There is an example of this situation at the bottom of the documentation:

# This code would be put in a button in the target that was retargeted to,
# and act as a 'back' button, that would retarget back to the original project.
 
# Fetch the global values that are automatically created when you retarget.
project = system.util.getGlobals()['_RETARGET_FROM_PROJECT']
gateway = system.util.getGlobals()['_RETARGET_FROM_GATEWAY']
  
# Retarget.
system.util.retarget(project, gateway)
1 Like