# Strange system.gui.transform behavior with templated instances

**URL:** <https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [July 15, 2025, 5:43pm UTC](https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509 "2025-07-15T17:43:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabien.lavoie](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@fabien.lavoie](https://forum.inductiveautomation.com/u/fabien.lavoie)\
**Post date:** [July 15, 2025, 5:43pm UTC](https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509/1 "2025-07-15T17:43:43Z")

</div>

I wanted to create an animated toggle button that would actually slide when toggled. This code is attached to a button's actionPerformed event handler. It just toggles a variable and slide over the object by it's own width when clicked:

```python
this = event.source
toggleState = not this.toggleState
this.toggleState = toggleState

if toggleState == False:
	target = this.x - this.width
	this.text = this.state0Text
elif toggleState == True:
	target = this.x + this.width
	this.text = this.state1Text
system.gui.transform(
    this,
    newX=target,
    duration=200,
    acceleration=system.gui.ACCL_EASE
)

```

This works perfectly fine when done directly in the editor.  
Then I wanted to template it and started getting really weird behavior when resizing the instance. The animation works fine if I keep the original size, but it breaks if I resize.

Even weirder, the breaking behavior is different if the objects are 'loose' or grouped within the template. See screenshots:

 ![non_templated](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/7/171a2a5a6e3aa82cd95e2fbc8887ddbf597f891e.png)  
 ![templated_loose](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/5/856b155de436cc50a81435c1859ed9da5070f20c.png)  
 ![templated_grouped](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/d/7ddbc62a13905af98127d997f8964185b777e1db.png)

As you can see, when templated, the button doesn't slide over the right amount. I added some print statements to check the values of 'this.x', 'this.width' and 'target'. The first time I click the button, the values appear correct, but the object doesn't actually gets moved the right amount, which throws off all subsequent toggles.

I'm even more perplexed at the behavior when the object is grouped within the template. Now not only the position is wrong, it also somehow scales the button, even though I'm not changing the scale in the code.

To reiterate, those are the exact same objects, with the same code, the only difference is being a template instance or not.

This was only a fun little test so I'm not too worried about keeping it non-templated, but I feel like this is either a bug or I'm wrong about the expected behavior.

Either way I appreciate any advice!

---

<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 15, 2025, 5:57pm UTC](https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509/2 "2025-07-15T17:57:23Z")

</div>

Add the `coordSpace` argument to the transform() call--you need designer coordinates for this.

---

<div class="post-metadata">

**Author:** ![fabien.lavoie](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@fabien.lavoie](https://forum.inductiveautomation.com/u/fabien.lavoie)\
**Post date:** [July 15, 2025, 6:24pm UTC](https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509/3 "2025-07-15T18:24:43Z")

</div>

Thanks for the reply, I used this code for the updated call and I still get the same behavior

```python
system.gui.transform(
    this,
    newX=target,
    duration=200,
    acceleration=system.gui.ACCL_EASE,
    coordSpace=system.gui.COORD_DESIGNER
)

```

---

<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 15, 2025, 6:36pm UTC](https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509/4 "2025-07-15T18:36:05Z")

</div>

Is the template configured to "allow layout" ?

---

<div class="post-metadata">

**Author:** ![fabien.lavoie](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@fabien.lavoie](https://forum.inductiveautomation.com/u/fabien.lavoie)\
**Post date:** [July 15, 2025, 7:19pm UTC](https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509/5 "2025-07-15T19:19:13Z")

</div>

It wasn't before. I enabled it and now it maintains aspect ratio when resizing, but I still get the same offset behavior.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/6/b67942b81b2b2789d686b6e910b4fbc9802fa624.png)

---

<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 15, 2025, 7:21pm UTC](https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509/6 "2025-07-15T19:21:19Z")

</div>

That might be the best you get. You may need to ensure it is always resized with fixed aspect ratio.

---

<div class="post-metadata">

**Author:** ![fabien.lavoie](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@fabien.lavoie](https://forum.inductiveautomation.com/u/fabien.lavoie)\
**Post date:** [July 15, 2025, 7:28pm UTC](https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509/7 "2025-07-15T19:28:58Z")

</div>

I can live with that, since it works fine when not in a template. Just wanted to make sure I wasn't doing something obviously wrong.

Thanks!

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [July 19, 2025, 3:47am UTC](https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509/8 "2025-07-19T03:47:33Z")

</div>

It's possible that this forum post could be applicable to this use case:  
[How to transform a component inside of a vision template](https://forum.inductiveautomation.com/t/how-to-transform-a-component-inside-of-a-vision-template/80122)

The problem is that the coordspace argument is always relative to the designer's window editor NOT the designer's template editor. As long as the template instance in the window is not stretched or squished when it's placed in the window, it will work fine, but if it has been resized after being dragged and dropped, then the transform will be off by that proportional amount.

---

<div class="post-metadata">

**Author:** ![fabien.lavoie](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@fabien.lavoie](https://forum.inductiveautomation.com/u/fabien.lavoie)\
**Post date:** [July 21, 2025, 3:32pm UTC](https://forum.inductiveautomation.com/t/strange-system-gui-transform-behavior-with-templated-instances/108509/9 "2025-07-21T15:32:22Z")

</div>

Thanks for the link, at least it confirms I'm not the only one that was perplexed by this behavior. I'll have to try your scaling solution if I ever come back to this.
