# Moving templates on window

**URL:** <https://forum.inductiveautomation.com/t/moving-templates-on-window/18808>\
**Category:** Ignition\
**Created:** [July 13, 2018, 1:22am UTC](https://forum.inductiveautomation.com/t/moving-templates-on-window/18808 "2018-07-13T01:22:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [July 13, 2018, 1:22am UTC](https://forum.inductiveautomation.com/t/moving-templates-on-window/18808/1 "2018-07-13T01:22:09Z")

</div>

Has anyone had success with moving templates on a window?  
I have tried a number of approaches as follows:

Template canvas  
Placing a template canvas on a window in the required location, or even spanning the entire window, allows moving the template. However we found it is impossible to locate the template accurately wrt graphical objects / components that are not templates (ie not on the canvas).

system.gui.transform() allows movement of templates, but again the coordinates seem to be unmanageable over window coordinates. Extending this approach, we used invisible lines as reverence x & y axes, and used transform() to move the template wrt to these axes. Again, we found this unreliable as templates moved to unexpected locations.

Any ideas would be greatly appreciated

---

<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:** [July 13, 2018, 12:13pm UTC](https://forum.inductiveautomation.com/t/moving-templates-on-window/18808/2 "2018-07-13T12:13:32Z")

</div>

Review every component involved and make sure anchored layout is selected. Only anchored layout coordinates match designer coordinates.

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [July 16, 2018, 3:55am UTC](https://forum.inductiveautomation.com/t/moving-templates-on-window/18808/3 "2018-07-16T03:55:25Z")

</div>

Thanks Phil  
Yes, that works, thanks  
However, my screen is rather complex with many components. To keep the screen appearance consistent ALL components would need to be anchored. This results in unacceptable layout.

What I find confusing is that I can use an expression binding on the ‘x’ property of a ‘normal’ component and this works fine, but it doesn’t work on a template

---

<div class="post-metadata">

**Author:** ![chris3145](https://avatars.discourse-cdn.com/v4/letter/c/96bed5/32.png) [@chris3145](https://forum.inductiveautomation.com/u/chris3145)\
**Post date:** [July 18, 2018, 6:30pm UTC](https://forum.inductiveautomation.com/t/moving-templates-on-window/18808/4 "2018-07-18T18:30:00Z")

</div>

When I had a template anchored to the bottom and right edges of a window, I had to negate some arguments in system.gui.transform().

The following code excerpt gets a button’s current coordinates, then “moves” the button to the coordinates that were just obtained. By all accounts, it looks like pointless code that wouldn’t do anything. But if the button is anchored to the right edge of the screen, this code snippet actually changes the x coordinate to the negative of whatever it was before. (E.g. If the button was at ( **40** , 120) this would move it to ( **-40** ,120), which is off the screen.)

```auto
oldBtnY = btn.getY()
oldBtnX = btn.getX()
system.gui.transform(component = btn, newX = oldBtnX, newY = oldBtnY)

```

The following code, meanwhile, seems like it would move the button to a negative x coordinate. But when it runs on a button anchored to the right edge of the screen, the button **does not** move at all:

```auto
oldBtnY = btn.getY()
oldBtnX = btn.getX()
finalBtnY = oldBtnY
finalBtnX = -oldBtnX # This needs to be negative because of the button being anchored to the right side of the screen.
system.gui.transform(component = btn, newX = finalBtnX, newY = finalBtnY)

```

Somebody who’s more competent with java might know a clever way to convert the coordinates automatically, but I stuck with manually programming negations in where I needed them.

---

<div class="post-metadata">

**Author:** ![Kevin.McClusky](https://avatars.discourse-cdn.com/v4/letter/k/47e85d/32.png) [@Kevin.McClusky](https://forum.inductiveautomation.com/u/Kevin.McClusky)\
**Post date:** [July 20, 2018, 12:49am UTC](https://forum.inductiveautomation.com/t/moving-templates-on-window/18808/5 "2018-07-20T00:49:46Z")

</div>

Try using the coordSpace argument.

system.gui.transform(event.source, 100, 200, coordSpace=system.gui.COORD\_DESIGNER)

[https://docs.inductiveautomation.com/display/DOC79/system.gui.transform](https://docs.inductiveautomation.com/display/DOC79/system.gui.transform)

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [July 30, 2018, 2:06am UTC](https://forum.inductiveautomation.com/t/moving-templates-on-window/18808/6 "2018-07-30T02:06:39Z")

</div>

Thanks Kevin  
That’s exactly what I needed.  
I thought I had read all the doco, but obviously missed that bit 🙂

Ross
