# Add templates to window via script

**URL:** <https://forum.inductiveautomation.com/t/add-templates-to-window-via-script/107621>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [June 20, 2025, 2:39pm UTC](https://forum.inductiveautomation.com/t/add-templates-to-window-via-script/107621 "2025-06-20T14:39:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![eiter](https://avatars.discourse-cdn.com/v4/letter/e/a3d4f5/32.png) [@eiter](https://forum.inductiveautomation.com/u/eiter)\
**Post date:** [June 20, 2025, 2:39pm UTC](https://forum.inductiveautomation.com/t/add-templates-to-window-via-script/107621/1 "2025-06-20T14:39:06Z")

</div>

I have an array of settings tags in my PLC, which are a combination of strings/dints/floats. I have a few settings template objects. I want to write a script that browses PLC tags, then adds the appropriate template object to my Settings screen. Is this possible? I would want it to look something like this:

```python
window = system.gui.getWindow("Settings")
tags = system.tag.browse("PLC/Settings",{})

for i in range(tags.count()):
    if tag.Type == 1:
        window.addTemplate("Setting_String", x, y)
    if tag.Type == 2:
        window.addTemplate("Setting_Int", x, y)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 20, 2025, 2:50pm UTC](https://forum.inductiveautomation.com/t/add-templates-to-window-via-script/107621/2 "2025-06-20T14:50:08Z")

</div>

That's what the template canvas is for. (You cannot add components to windows at runtime.)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 20, 2025, 3:00pm UTC](https://forum.inductiveautomation.com/t/add-templates-to-window-via-script/107621/3 "2025-06-20T15:00:36Z")

</div>

Welcome to the forum. Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). Then you can edit your post (pencil icon) to fix it. It may help someone else in future.

---

<div class="post-metadata">

**Author:** ![eiter](https://avatars.discourse-cdn.com/v4/letter/e/a3d4f5/32.png) [@eiter](https://forum.inductiveautomation.com/u/eiter)\
**Post date:** [June 20, 2025, 3:18pm UTC](https://forum.inductiveautomation.com/t/add-templates-to-window-via-script/107621/4 "2025-06-20T15:18:24Z")

</div>

Is there no way to do this in the designer script window also then? I was thinking I could just script it while designing and return to it if I have UDT changes. I'm having a hard time with the template canvas. I can't figure out how to have a string/int setting object but hide visibility of one. I'm also trying to pass a tag through the template canvas to the template but the tag doesn't seem to be linking

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 20, 2025, 3:28pm UTC](https://forum.inductiveautomation.com/t/add-templates-to-window-via-script/107621/5 "2025-06-20T15:28:21Z")

</div>

> [@eiter](#):
>
> Is there no way to do this in the designer script window also then?

Not reliably, no, and not supported. Not impossible, but you have to go way under the hood, and have to be comfortable with java Swing.

---

<div class="post-metadata">

**Author:** ![eiter](https://avatars.discourse-cdn.com/v4/letter/e/a3d4f5/32.png) [@eiter](https://forum.inductiveautomation.com/u/eiter)\
**Post date:** [June 20, 2025, 3:58pm UTC](https://forum.inductiveautomation.com/t/add-templates-to-window-via-script/107621/6 "2025-06-20T15:58:58Z")

</div>

Can I modify the properties on objects from the scripting? So if I make a generic setting template, can I script through and set the template properties to the objects after I've added them to the window?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 20, 2025, 4:15pm UTC](https://forum.inductiveautomation.com/t/add-templates-to-window-via-script/107621/7 "2025-06-20T16:15:14Z")

</div>

> [@eiter](#):
>
> I'm having a hard time with the template canvas. I can't figure out how to have a string/int setting object but hide visibility of one. I'm also trying to pass a tag through the template canvas to the template but the tag doesn't seem to be linking

The final argument in the template canvas' dataset is a JSON string (because Vision lacks true multidimensional property support).

So I would say you should be constructing a json value for each row that looks like this:

```python
{
"shouldBeVisible": true,
"tagPath": "path/to/tag"
}

```

Updating the template canvas dataset dynamically from the outside using whatever script you feel like.  
Inside the template, use indirect tag bindings to reference actual tag values using the input tagPath parameter, and bind your template's overall visibility to the `shouldBeVisible` value. If you add `hidemode 3` to your template canvas' overall "layout constraints" property, invisible components will not participate in layout.

---

<div class="post-metadata">

**Author:** ![eiter](https://avatars.discourse-cdn.com/v4/letter/e/a3d4f5/32.png) [@eiter](https://forum.inductiveautomation.com/u/eiter)\
**Post date:** [June 20, 2025, 6:18pm UTC](https://forum.inductiveautomation.com/t/add-templates-to-window-via-script/107621/8 "2025-06-20T18:18:57Z")

</div>

The indirect tags fixed this for me, thanks! I ended up just copy/pasting a single template object in multiple times, the canvas object didn't end up being necessary. For the curious, here was my final script. Still adding in the type verification from the PLC tag

```python
window = system.gui.getWindow("Settings_Recipe/_StdSettings")
rc = window.getRootContainer()
cont = rc.getComponent("Settings")

for i in range(20):
	setting = "TN_Setting " + str(i)
	comp = cont.getComponent(setting)
	comp.setPropertyValue("TagPath", "[default]OvenPLC/HMI/Settings/Setting" + '{:03d}'.format(i))

```
