# Using script to create a template instance?

**URL:** <https://forum.inductiveautomation.com/t/using-script-to-create-a-template-instance/10217>\
**Category:** Ignition\
**Created:** [July 13, 2015, 6:42pm UTC](https://forum.inductiveautomation.com/t/using-script-to-create-a-template-instance/10217 "2015-07-13T18:42:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bokechal](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@bokechal](https://forum.inductiveautomation.com/u/bokechal)\
**Post date:** [July 13, 2015, 6:42pm UTC](https://forum.inductiveautomation.com/t/using-script-to-create-a-template-instance/10217/1 "2015-07-13T18:42:40Z")

</div>

Hi there,  
Is there a script command to create a template instance?

I’m dealing with a project to create input boxes based on the result I query from other system.  
For example, there are 4 items returned from the query and each item has different number of inputs required. Something like

item1 requires 2 input boxes  
item2 requires 1 input boxes  
item3 requires 10 input boxes  
item4 requires 5 input boxes

My idea is to create a template with dropdown list and text input components. Each template is for each item and dropdown list will be a number of inputs required. User will be select number and enter value in the text input components then store as a dataset or dictionary type.

I want to be able to create template instance from script based on the number of items returned.

If there are any other better ways to do, please suggest.

---

<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:** [July 13, 2015, 7:05pm UTC](https://forum.inductiveautomation.com/t/using-script-to-create-a-template-instance/10217/2 "2015-07-13T19:05:23Z")

</div>

The recommended approach is to use the Template Canvas or Template Repeater to dynamically create template instances. Here’s a tutorial on the Template Canvas: [nickmudge.info/post/ignitions-te … at-runtime](http://nickmudge.info/post/ignitions-template-canvas-dynamically-creating-screens-at-runtime)

Best,

---

<div class="post-metadata">

**Author:** ![bokechal](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@bokechal](https://forum.inductiveautomation.com/u/bokechal)\
**Post date:** [July 14, 2015, 9:11pm UTC](https://forum.inductiveautomation.com/t/using-script-to-create-a-template-instance/10217/3 "2015-07-14T21:11:31Z")

</div>

Thank you Nick, stuff in your link is very helpful.

---

<div class="post-metadata">

**Author:** ![scicco](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@scicco](https://forum.inductiveautomation.com/u/scicco)\
**Post date:** [July 15, 2015, 6:07pm UTC](https://forum.inductiveautomation.com/t/using-script-to-create-a-template-instance/10217/4 "2015-07-15T18:07:46Z")

</div>

I would like to recreate the Template Canvas Customizer in a client window to give users the ability to build dashboards on their own without the designer.

I think I can do just about everything to populate the Templates dataset except for providing the drop-down of available templates and then expose the selected template’s parameters. I know I could build database tables pre-populated with template names and parameters but was hoping to just use whatever the customizer is using.

Thanks in advance -

---

<div class="post-metadata">

**Author:** ![Amarth](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarth/32/3313_2.png) [@Amarth](https://forum.inductiveautomation.com/u/Amarth)\
**Post date:** [September 1, 2015, 9:34am UTC](https://forum.inductiveautomation.com/t/using-script-to-create-a-template-instance/10217/5 "2015-09-01T09:34:34Z")

</div>

I’m looking for this drop down as well ([Here](https://inductiveautomation.com/forum/viewtopic.php?f=70&t=14121)). I had a quick look in the SDK documentation without success so far…

---

<div class="post-metadata">

**Author:** ![scicco](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@scicco](https://forum.inductiveautomation.com/u/scicco)\
**Post date:** [September 1, 2015, 11:50am UTC](https://forum.inductiveautomation.com/t/using-script-to-create-a-template-instance/10217/6 "2015-09-01T11:50:15Z")

</div>

You’d need to do something in addition to this for the UDT association but this will list templates from the designer. I think I got it from Nick originally but don’t see that post anymore. This is on the mousePressed event of a drop-down:

[code]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

#Get templates from Gateway  
l = []  
templatePaths = getProjectTemplates(event)  
for path in templatePaths:  
if path.startswith(“Dashboard/”):  
#Use specific folder to hold all Dashboard-related templates  
l.append([path])

data = system.dataset.toDataSet([“Value”], l)  
event.source.data = data[/code]

---

<div class="post-metadata">

**Author:** ![Amarth](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarth/32/3313_2.png) [@Amarth](https://forum.inductiveautomation.com/u/Amarth)\
**Post date:** [September 2, 2015, 3:10pm UTC](https://forum.inductiveautomation.com/t/using-script-to-create-a-template-instance/10217/7 "2015-09-02T15:10:49Z")

</div>

Thank you for the reply. It helped a lot.

I’ll keep looking for the UDT association and will post here if I find something interesting.
