I dug into the Ignition and Java objects and found a way to get a list of all the template paths that exist in a project.
The following function can be used in an event handler to get a list of all the templates in the current project. It works in the client and designer:
def getProjectTemplates(event):
import system
comp = event.source
if system.util.getSystemFlags() & system.util.DESIGNER_FLAG:
from com.inductiveautomation.ignition.designer import IgnitionDesigner
while not isinstance(comp,IgnitionDesigner):
comp = comp.parent
context = comp.getContext()
else:
from com.inductiveautomation.factorypmi.application.runtime import ClientPanel
while not isinstance(comp,ClientPanel):
comp = comp.parent
context = comp.getClientContext()
project = context.getProject()
templates = project.getResourcesOfType("fpmi","component-template")
templatePaths = [project.getFolderPath(template.getResourceId()) for template in templates]
return templatePaths
l = []
templatePaths = getProjectTemplates(event)
for path in templatePaths:
l.append([path])
data = system.dataset.toDataSet(["Value"], l)
event.source.getComponent('Dropdown').data = data
After the function definition the code shows how to make a dataset out of the list of template paths and assigns the dataset to a dropdown.
By binding a template’s templatePath property to the dropdown’s selectedStringValue it is possible to switch a template in a window to any template that exists in the project by selecting different template paths in the dropdown.
Nick