Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Scripting_function


Panel
titleDescription

Retrieves Tags from the Gateway as Python dictionaries. These can be edited and then saved back using system.tag.configure.

Note_friendly

The configurations returned by this function can only contain properties that are not using their default values. Thus, if a property on a tag has not been modified from its default value, then it will not be included in the returned list. 

Should you need to read the value of a tag property, regardless of whether it's using the default value or not, use system.tag.readBlocking instead:

Code Block
system.tag.readBlocking(["[default]path/to/tag.engUnit"])
Client permissions restrictions


Panel
titleSyntax

system.tag.getConfiguration(basePath, recursive)

  • Parameters

String basePath - The starting point where the Tags will be retrieved. This can be a folder containing, and if recursive is true, then the function will attempt to retrieve all of the Tags in the folder.

Boolean recursive If true, the entire Tag tree under the specified path will be retrieved. 

  • Returns

List - A List of Tag dictionaries. Nested Tags are placed in a list marked as "tags" in the dictionary.

  • Scope

Gateway, Vision Client, Perspective Session

Panel
titleCode Examples
Code Block
languagepy
titlePython - Access a Single Property on a Single Tag
# This example will look up the name property on a Tag. 

path = '[default]My_Folder/My_Tag'

config = system.tag.getConfiguration(path, False)

# While the call above was directed at a single Tag, the function
# still returns a list, so we access index 0 to examine the properties
# (hence the "[0]"). 
#
# Additionally, we can access the name property in a similar manner 
# to accessing a key in a Python Dictionary. 

print config[0]['name']
Code Block
languagepy
titlePython - Get All Properties for a Single Configuration
# This example will get the configuration of a single Tag

# Update the path here with the Tag path you're trying to reach
path = '[default]Sine/Sine0'

# Get the configurations
tags = system.tag.getConfiguration(path)

for tagDict in tags:
	
    # Iterate over the dictionary with the iteritems function
    for key, value in tagDict.iteritems():
		
        # Do something with the keys and values
        print key, ' : ', value
Code Block
languagepy
titlePython - Return an Entire Folder of Tag Configurations
# This example will get the configurations of Tags under a folder. 

# Update the path here with the folder you want to start at
folder = '[default]Folder/Another_Folder'

# Get the configurations. We'll specify True for the second parameter to search 
# recursivly
nodes = system.tag.getConfiguration(folder, True)

# Iterate over the results
for item in nodes:
	
    # Through the results, search each dictionary
    for key, value in item.iteritems():
		
		# ...looking for a 'tags' key
		if key == 'tags':
			print '#######Found some tags!#######'
				
			# iterate over the Tag configurations we found
			for tagConfig in value:
				
				# Do something with the results.
				print tagConfig["name"]
Code Block
languagepy
titleExample - UDT Parameters and Bindings
# This example configure bindings that make use of three UDT parameters. 
tag = {
  "name": "UDTName",
  "parameters": {
    "device": {
      "dataType": "String",
      "value": "[Sample_Device]"
    },
    "opcPath": {
      "dataType": "String",
      "value": "_Meta:Ramp/Ramp0"
    },
    "opcServer": {
      "dataType": "String",
      "value": "Ignition OPC UA Server"
    }
  },
  "tagType": "UdtType",
  "tags": [
    {
    # Creating a binding involves change the key to an object, with a "bindType" key set to "parameter", and a 
	#  "binding" key set to the binding. Note that the actual binding can consist multiple parameters and characters
      "opcItemPath": {
        "bindType": "parameter",
        "binding": "{device}{opcPath}"
      },
      "opcServer": {
        "bindType": "parameter",
        "binding": "{opcServer}"
      },
      "valueSource": "opc",
      "name": "New Tag",
      "tagType": "AtomicTag"
    }
  ]
}

path = "[default]"
system.tag.configure(path, [tag], "o")
Panel
titleKeywords

system tag getConfiguration, tag.getConfiguration