# How to get project object using script

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-project-object-using-script/7472>\
**Category:** Ignition\
**Created:** [October 26, 2013, 12:19pm UTC](https://forum.inductiveautomation.com/t/how-to-get-project-object-using-script/7472 "2013-10-26T12:19:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumit](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@sumit](https://forum.inductiveautomation.com/u/sumit)\
**Post date:** [October 26, 2013, 12:19pm UTC](https://forum.inductiveautomation.com/t/how-to-get-project-object-using-script/7472/1 "2013-10-26T12:19:23Z")

</div>

How to get project object using script

What I want to do is using the project object, get “templates” name on drop down, so user can select the template clicking on drop down

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [December 26, 2013, 6:45pm UTC](https://forum.inductiveautomation.com/t/how-to-get-project-object-using-script/7472/2 "2013-12-26T18:45:21Z")

</div>

There’s a way to get the project’s windows ( system.gui.getWindowNames() ), but unfortunately there is no function to get all of the template names. You could just use a static list of your templates in a dropdown component.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [December 27, 2013, 4:25pm UTC](https://forum.inductiveautomation.com/t/how-to-get-project-object-using-script/7472/3 "2013-12-27T16:25:32Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [December 27, 2013, 4:57pm UTC](https://forum.inductiveautomation.com/t/how-to-get-project-object-using-script/7472/4 "2013-12-27T16:57:44Z")

</div>

Note that there is no guarantee that this code will continue to work after any upgrade, and is not officially supported. I highly recommend against using it unless you are familiar with the SDK.

---

<div class="post-metadata">

**Author:** ![ericleisebein](https://avatars.discourse-cdn.com/v4/letter/e/cc9497/32.png) [@ericleisebein](https://forum.inductiveautomation.com/u/ericleisebein)\
**Post date:** [April 7, 2020, 9:05am UTC](https://forum.inductiveautomation.com/t/how-to-get-project-object-using-script/7472/5 "2020-04-07T09:05:28Z")

</div>

As Robert already mentioned, this code unfortunately isn’t working anymore under Ignition 8 you have to pass a ressourceType object. Creating this object with “fpmi”,“component-template” will give back an empty list.  
Since I didn’t find the API documentation for Ignition 8 yet I can’t get this to work. I guess the only thing that is missing is the correct type identifier for templates in Ignition 8.  
Any ideas what that could be?
