How can I check if a view is available using expressions or scripts? For instance, if I pass dynamic view names to an embedded view, I want to validate if the view exists in the project views. Rather than allowing Ignition to throw a "view not found" error, I would like to handle this scenario with a custom message.
This is the function I use:
def exists(viewPath):
for view in system.perspective.getProjectInfo().views:
if view['path'].lower() == viewPath.lower():
return True
return False
2 Likes
Thanks, Nick
Minor golf:
def exists(viewPath):
needle = viewPath.lower()
return any(view['path'].lower() == needle for view in system.perspective.getProjectInfo().views)
Lowering the search string only once is also a micro-optimization
2 Likes