Creating the paths in Tree View Component from the nodes in a OPC Server?


I’m trying to browse the OPC server pull the nodes that are folders which the “system.opc.browseServer” is seeing as “OBJECTS” and then construct the necessary paths that could be used in the TREE VIEW component? I’m using recursion to do this because originally I was using a nested for-loop but I can only browse so far in the OPC server.
With recursion I can never construct the path correctly such as “root/child/child/child” and then add that path to a list?

#This code should browse the nodes in the server that are folders and start creating the directory path from the root.
#The code will then construct a dataset to be used in the tree browse component.
#format should be [root/child/child,root/child/child,........,Npath] in List

OPCServerName = "LINX-7923 Server"

#start from the root
NodeId = ""

def browseServer(nodeId):
	pathList = []
	children = system.opc.browseServer(OPCServerName, nodeId)
	for child in children:
		elementType = str(child.getElementType())#SEES FOLDERS AS TYPE OBJECTS INSTEAD OF TYPE "FOLDER"
		childNodeId = str(child.getServerNodeId().getNodeId()) #Get the Node ID ex: n=1;i=x
		folderName = str(child.getDisplayName())#get the string name of the node in the server
		if elementType == "OBJECT": #all folders are treated as objects that's why im doing this comparing
			pathList.append(folderName) #"/"+str(browseServer(childNodeId))
	return pathList

PathList = browseServer(NodeId)
for path in PathList:
	print path

When using recursion alot of processor power from the gateway is used, is it better to run this code on a different thread so I don’t overload the gateway such as with “system.util.invokeAsynchronous”

Haven’t looked at the code yet, but if this is currently running on the GUI yes absolutely you’ll want to run this asynchronously.

I assume that since you say this is already running on the gateway that this is for perspective? Or is this running in a gateway event of some type? If that is the case then in may already be running asynchronously.

This is just a tag creation tool that will only run in the designer, it triggers off button events, its not an actual graphic.