Get List of all views in a perspective App

Hello All,

Looking for a way to get a list of all views in a perspective application. Furthermore, can I specify a specific location to loop through the views. Like a folder of views within the project? Thanks in advance.

Frank

By conventional methods is not possible I think, I tried with “advanced methods” not success yet. I don’t know if it even possible or secure to do because the only scope who needs to know all available views is the designer.

You can use system.perspective.getProjectInfo()

https://docs.inductiveautomation.com/display/DOC81/system.perspective.getProjectInfo

3 Likes

Ops

Of course you can do that.
Just download HMI framework resource from echange and there is script to show you how to do this. Even you can loop through objects inside view

The perspective code run in server side so you can get result only if run it in perspective scope or gateway

Bind the following code to the 'props.items' Tree component and it will create a tree view of the entire project. It is also possible to add pages by changing the code. This simple code took a few hours to write. If you improve the code, please share it.

def transform(self, value, quality, timestamp):

	v = []
	for item in system.perspective.getProjectInfo()['views']:
		v.append(item['path'].split('/'))
	return returnViews(v)

def	items(label,items,data):

		return {
			      "label": label,
			      "expanded": True,
			      "data" : data,
			      "items": items,
			    }

def returnViews(viewsArray):

	chieldItem = []
	pastItem = ''
	idx2 = 0
	v1 = []
	firstMulti = True
	lastFolder = False
	pastFolderName = ''
	viewsArraySize = 0
	chieldItemLast = []
	itemLast = 0
	
	idx = 0
	for idx, item in enumerate( viewsArray):
					
		if len(viewsArray[idx])==idx2+1:
			v1.append(items(viewsArray[idx][idx2+0],[],'1'))
			
		if len(viewsArray[idx])>idx2+1:
		  	if (pastItem != viewsArray[idx][idx2+0]) and len(chieldItem)>0:
		  		chieldItem.append([''])	
				v1.append(items(pastItem,returnViews(chieldItem),'2'))
				chieldItem= []
				pastItem = viewsArray[idx][idx2+0]
				
			viewsArraySub1Column = list(viewsArray[idx])
			del viewsArraySub1Column[0]
			chieldItem.append((viewsArraySub1Column))	
			
				
	  	if (pastItem != viewsArray[idx][idx2+0]) and chieldItem != []:
	  		if firstMulti == False:
	  			chieldItem.append([''])	
				v1.append(items(pastItem,returnViews(chieldItem),'3'))
				chieldItem=[]
				firstMulti = True
			else:
	  			firstMulti = False

		pastItem = viewsArray[idx][idx2+0]
		idx = idx + 1
	return (v1)

3 Likes