Check to see if template path exists?

As long as we’re golfing, this should also work and be marginally more efficient (short circuits, plus doesn’t build a list in memory):

def template_exists(template_path):
	"""
	Syntax: template_exists(template_path)

	Parameter:
	template_path: A string of the template's name. If in a directory prefix with the directory name: path/to/template

	Return Type: This method returns a Boolean value of class bool. This method returns True if the template exists otherwise returns False. 
	"""
	from com.inductiveautomation.factorypmi.application.model import TemplateManager
	
	context = event.source.getAppContext()
	project = context.getProject()
	resources = project.getResourcesOfType(TemplateManager.RESOURCE_TYPE)
	return any(template_path in resource.folderPath for resource in resources)

print template_exists('foo')
1 Like