[feature-781]Perspective: Check if Embedded View 'path' is valid?

v8.1rc1

Is it possible to check if an Embedded View path property value is valid? I want to hide the component if it’s not, as I’m using a generic structure to generate the path, where some instances don’t have the item.

Essentially, I’m asking if there’s a function to check if a View path exists?

Also, can I get the view path of an open view? As in the path seen in the Designer project tree:
For this below, it would be Winery/Tank Farms/Main
image

I filed an internal ticket a long time ago to add a system.perspective.getViewNames() or similar tool for introspection, along the lines of the Vision function. That’s probably your best bet here.

1 Like

I posted a proposal on another thread that I think will solve this ask.

Was anything like this ever implemented? I’m running into the same issue again (albeit in 8.1.5) where I’m using an Embedded View where the view path is dynamic. Often the path will be invalid (which is valid) and in these cases I want to hide the embedded view. I don’t see a way to do this. For me, an expression function viewExists('Path/To/View') would be great here to have

Maybe there is a easier way but this works xd
It checks if the resource folder of the view exists^^

	def viewExists(viewpath):	
		from com.inductiveautomation.ignition.gateway import IgnitionGateway			
		context = IgnitionGateway.get()	
		pathToProjectFolder = str(context.systemManager.dataDir.absoluteFile).replace('\\','/') + '/projects'	
		pathToProject = pathToProjectFolder + "/" + system.perspective.getProjectInfo().name + "/com.inductiveautomation.perspective/views/"
		return system.file.fileExists(pathToProject + viewpath)
2 Likes

Haha, that’s works. I didn’t even think about doing it that way, cheers. I’ll use that for now

I guess for speed I could cache a list of all views found updated periodically or on trigger (eg designer save) and then read from that instead. I’ll see what kind of delay I get, shouldn’t be too bad though!

1 Like

i dont think there is going to be any noticable delay. but i havent tested it with crazy deep folders xd

it just takes about a milisecond or 2 for my views so xd
image

image

My operators will probably still complain :joy:

3 Likes

average human reaction time is about 250milisec so i think you’re safe :stuck_out_tongue:
even the fastest reacting animals (fruit flies?) need 5ms

1 Like

system.perspective.getProjectInfo() returns a views array, you can check that for the view. Probably substantially faster than filesystem access.

2 Likes

Apparently yes, Carl posted this in the thread he linked:

1 Like

It seems to be going a tiny bit faster. Tho you gotta itterate over an array of dicts so if you got many views idk if it will be actually faster.

def viewExists(view):
	return any(x.path == view for x in system.perspective.getProjectInfo().views)

6 posts were split to a new topic: Jython filtering profiling