Global Dictionary

Scripting is not supported by TWC

Canvas provides Screen methods to save a complex script object to a global dictionary and to read the object from another screen:

The dictionary object is saved in the application’s memory and is available as long as the instance of the application is open.

WriteToGlobalDictionary Method

The WriteToGlobalDictionary method saves a complex script object to a global dictionary in the Canvas application’s memory.

See Global Dictionary for more information about using this method.

Syntax

Objects.Screen.WriteToGlobalDictionary("object", Objects.ControlName.Text);

Example — Writing to the global dictionary

The following example code snippet writes the value "STUFF" from the EditBox1 to the global dictionary:

Copy
Writing to the global dictionary
public ScreenClass()
{
    // control event handler code goes here -- do not modify
    Objects.Button2.Click += new EventHandler(this.Button2_Click);
    // add your custom initialization code here
}
#region Button2
private void Button2_Click(object sender, EventArgs args)
{
    Objects.Screen.WriteToGlobalDictionary("STUFF", Objects.EditBox1.Text);
}
#endregion

ReadFromGlobalDictionary Method

The ReadFromGlobalDictionary method reads a complex script object from another screen.

See Global Dictionary for more information about using this method.

Syntax

Objects.ControlName.Text = (string)Objects.Screen.ReadFromGlobalDictionary("object");

Example — Reading from the global dictionary

The following example code snippet retrieves the value "STUFF" from the global dictionary and passes it to TextTool1:

Copy
Reading from the global dictionary
public ScreenClass()
{
    // control event handler code goes here -- do not modify
    Objects.Button2.Click += new EventHandler(this.Button2_Click);
    // add your custom initialization code here
}
#region Button2
private void Button2_Click(object sender, EventArgs args)
{
    Objects.TextTool1.Text = (string)Objects.Screen.ReadFromGlobalDictionary("STUFF");
}
#endregion

GetGlobalDictionary Method

The GetGlobalDictionary method returns the dictionary itself, allowing a script writer to manipulate the dictionary directly or inspect its contents.

Example

Copy
GetGlobalDictionary method
public Canvas.Shared.CanvasGlobalDictionary GetGlobalDictionary()

The Canvas.Shared class, "CanvasGlobalDictionary," is a C# System.Collections.Generic.Dictionary<string, object>. The string represents the key and the object represents the value. This collection allows you to store any data you want and reference it later by the key assigned when it was added. If the same key is used multiple times, the original value would be replaced by the latest update.

See Global Dictionary for more information about using this method.

Global Dictionary Example

In a traditional HMI workflow, you might create a screen that contains a faceplate to display some specific contextual information, for example, a digital valve control faceplate. You may not always be guaranteed that the UDC will be the same, and there are only so many ways a digital valve operates (on or off, open or closed, etc. …).

You can create a templated screen to which you can hyperlink, and you need to pass in the appropriate UDC to display. Set the UDC in the global dictionary, issue the hyperlink, and then retrieve the UDC from the global dictionary on the hyperlinked screen.

Set the value in the global dictionary with a command like this:

Copy
WriteToGlobalDictionary
Objects.Screen.WriteToGlobalDictionary("ValveUdc", Objects.SourceTextTool.PointConfiguration.UDC);

Then issue a command like this, to retrieve the UDC and set a control (for example, a Text Tool) with the value:

Copy
DestinationTextTool.PointConfiguration.UDC
Objects.DestinationTextTool.PointConfiguration.UDC = (string)Objects.Screen.ReadFromGlobalDictionary("ValveUdc");

Also see Hyperlinking Screens.