How can I validate if a view exist in the project folder with perspective

Is ther a way to valide that a view exist?

Actually I use a script with hardcoded path, but I search a way to do that more efficially with binding path.

My script;
path = “C:/Program Files/Inductive Automation/Ignition/data/projects/AMT/com.inductiveautomation.perspective/views/1-UDTS\AS0153_TRIM_PRESS/SETUP/Elems”

value = system.file.fileExists(path + “/Extras/ejector_closed_position”)
return value

I have a button that I want to root to a specific view if the view exit.

Anyone have better solution for me?

You should be putting all of your code within preformatted text characters ``

This = some_code
If you_add:
       Tabs = 'they remain intact' 

I don’t understand your explanation. How can I validate if a view exist in a specific folder of my project?

He’s saying you should post your code by putting it between

```

my code here

```
so that it gets formatted and we can read it better

From your post its hard to tell exactly what your script is, how it’s being called, if its inside a function, etc. However, I think it sounds like you just want a function that checks if a file exists? system.file.fileExists already does that. But if you ar einclined to make your own function, you can do

def fileExists(filePath):
    """
    Checks if a file exists.
    Args:
        filePath: str, file path to check
    Returns:
        boolean, true if file exists, false otherwise
    """
    import system.file
    return system.file.fileExists(filePath)

I know that and I want to build my own function, but I don’t want to have to specified the local path of my perspective project manually. I search a way to be able to get the direct path to my perspective project folder.

def transform(self, value, quality, timestamp):
	"""
	self.view.custom_view_path = C:/Program Files/Inductive Automation/Ignition/data/projects/AMT/com.inductiveautomation.perspective/views/

    I search a way to get that path withaout having to declared it manually.  How to get perspective view path of my project?
	"""
	viewPath = "1-UDTS/AS0153_TRIM_PRESS/SETUP/Elems/Extras/"
	fullPath = self.view.custom.views_path +  viewPath
	tags = system.tag.browseTags(parentPath=value["items_path"])
	
	tags_dict = {}			
	for tag in tags:
		if value["mode_text"]=="install":
			if self.parent.custom.when==self.parent.custom.constants_setup_item_when.always or self.parent.custom.when==self.parent.custom.constants_setup_item_when.install_only:
				add_need=True
			else:
				add_need=self.view.custom.show_all
		elif value["mode_text"]=="uninstall":
			if self.parent.custom.when==self.parent.custom.constants_setup_item_when.always or self.parent.custom.when==self.parent.custom.constants_setup_item_when.uninstall_only:
				add_need=True
			else:
				add_need=self.view.custom.show_all		
		else:
			add_need=self.view.custom.show_all
						
		if add_need:
			tags_dict[tag.fullPath] = system.tag.read(tag.fullPath + "/preset/sort_order").value
		
	tags_sorted = sorted(tags_dict.items(), key=lambda x: x[1])
	
	instances = []
	for k, v in list(tags_sorted):
			my_dict={}
			my_dict["instanceStyle"]={}
			my_dict["instanceStyle"]["classes"]=""
			my_dict["instancePosition"]={}
			my_dict["title"] = "tp_setup_" + k.rsplit("/",1)[1] + "_title"
			my_dict["description"] = "tp_setup_" + k.rsplit("/",1)[1] + "_" + value["mode_text"]
			my_dict["item_path"] = k
			my_dict["popUp"]=self.view.custom.popUp
			my_dict["show_all"]=self.view.custom.show_all
			my_dict["clic_enabled"]=self.view.custom.clic_enabled
			my_dict["path"]=self.view.params.path
			my_dict["access_role"]=self.view.params.access_role
			my_dict["needs_type"]=value["needs_type"]
			my_dict["mode_text"]=value["mode_text"]
			
			if system.file.fileExists(fullPath + k.rsplit("/",1)[1] + "_" + value["mode_text"]):
				my_dict["custom_view_exist"] = True
				my_dict["custom_view_name"] = viewPath + k.rsplit("/",1)[1] + "_" + value["mode_text"]
			else:
				my_dict["custom_view_exist"] = False
				my_dict["custom_view_name"] = None
			instances.append(my_dict)
	
	return instances