# This example attempts to recursively browse OPC nodes. Be mindful of the maxDepth in larger systems.
# The example uses system.util.getLogger asynchronously, so if you're calling this in the Script Console,
# the output may appear in a different console (i.e., Designer console).
from functools import partial
maxDepth = 1 # Determines how deep the browse will go
serverName = 'Ignition OPC UA Server'
myLogger = system.util.getLogger('My Browse') # Creating a logger to print the results
# Determines where the browse should start. An empty string will start at the root.
# Alternatively, '[device name]' will start at a certain device.
root = ''
def browse(nodeId, depth = 0):
children = system.opc.browseServer(serverName, nodeId)
for child in children:
elementType = str(child.getElementType())
childNodeId = child.getServerNodeId().getNodeId()
msg = 'Depth - %s, Node - %s' % (depth, childNodeId)
myLogger.info(msg)
# If the element is a folder, try to browse deeper.
if (elementType == 'FOLDER' and depth < maxDepth):
browse(childNodeId, depth + 1)
system.util.invokeAsynchronous(partial(browse, root))