# \[SOLVED\] Vision Animation using system.gui.moveComponent

**URL:** <https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022>\
**Category:** Ignition\
**Created:** [July 23, 2020, 10:15pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022 "2020-07-23T22:15:39Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 23, 2020, 10:15pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/1 "2020-07-23T22:15:39Z")

</div>

After reading the literature I was under the impression the following code:

```
rect = event.source.parent.getComponent("template_Instruction1")
system.gui.moveComponent(rect, rect.x, rect.y)

```

tied to a button would move the component ‘template\_Instrution1’ to the SAME position. However, at run time the component moves closer to the top right of the screen.

What gives here?

---

<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:** [July 23, 2020, 10:57pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/2 "2020-07-23T22:57:12Z")

</div>

`moveComponent` is deprecated - use [`system.gui.transform`](https://docs.inductiveautomation.com/display/DOC80/system.gui.transform), and pay attention to the ‘coordinate space’ parameter.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 23, 2020, 11:00pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/3 "2020-07-23T23:00:45Z")

</div>

Far easier than what I had planned to do. Thank you.

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

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 24, 2020, 3:29pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/4 "2020-07-24T15:29:46Z")

</div>

```
#GET COMPONENT
component1 = event.source.parent.getComponent('Rectangle1')

#SET PARAMETERS TO PASS INTO system.gui.transform()
t_X = component1.relX
t_Y = component1.relY
t_Width = component1.relWidth
t_Height = component1.relHeight
t_Duration = 1000
t_Callback = None
t_FPS = 60
t_Accel = system.gui.ACCL_CONSTANT
t_Coord = system.gui.COORD_DESIGNER

system.gui.transform(
    	component = component1,
    	newX = t_X,
    	newY = t_Y,
    	newWidth = t_Width,
        newHeight = t_Height,
    	duration = t_Duration,
    	callback = None,
    	framesPerSecond = t_FPS,
    	acceleration = t_Accel
        coordSpace = t_Coord
)

```

I believe the above code should keep Rectangle1 at the same X,Y coordinates but it moves still with my button that triggers the code… I think this is because I have a docked window in my project on the left side. The size of the docked window is 200x1080. The size of the window running the animation is 1720x1080. The total size of the project should be 1920x1080.

Thoughts on this?

EDIT: UPDATED WITH SOLUTION

---

<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:** [July 24, 2020, 3:31pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/5 "2020-07-24T15:31:09Z")

</div>

You’re not passing the `t_Coord` parameter in - you’ve tried both ways?

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 24, 2020, 3:33pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/6 "2020-07-24T15:33:01Z")

</div>

Ahhhh im blind.

That was the solution thanks. I’ll update the code above to include the t-coord.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 24, 2020, 9:02pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/7 "2020-07-24T21:02:02Z")

</div>

What is the difference between these two?

```
rectX = rectangle[temp[x]].relX
rectY = rectangle[temp[x]].relY
rectWidth = rectangle[temp[x]].relWidth
rectHeight = rectangle[temp[x]].relHeight

```

and…

```
rectX = rectangle[temp[x]].getX()
rectY = rectangle[temp[x]].getY()
rectWidth = rectangle[temp[x]].getWidth()
rectHeight = rectangle[temp[x]].getHeight()

```

Because the “relX” from the first block doesn’t exist for templates on the screen. But when I use “getX()” from the second block to transform a template it doesn’t quite move to the correct location. I’m assuming “getX()” is calling the position relative to the Root container?

---

<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:** [July 24, 2020, 9:14pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/8 "2020-07-24T21:14:38Z")

</div>

Welcome to the wonderful world of relative coordinate systems 🙂  
The `rel<X/Y/width/height>` options are only present on shapes, because of…reasons.  
An X position of a component should be relative to its container - which may or may not be the root container; for templates it almost certainly isn’t.  
You could try importing and using [`SwingUtilities.convertPoint`](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/SwingUtilities.html#convertPoint(java.awt.Component,int,int,java.awt.Component)) - move from the given coordinate system to the actual root container’s coordinate system.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 24, 2020, 9:22pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/9 "2020-07-24T21:22:58Z")

</div>

> [@paul-griffith](#):
>
> SwingUtilities.convertPoint

This is slightly above my current coding abilities. Care to post an example?

My alternate solution I've been working on is having invisible rectangles on the screen that I can send the templates too.

All this to create a scrolling like menu for the user 😅  
Simple example: I have rectangle 1, 2, 3 and template 1, 2, 3. Template 1 moves to rectangle 3. Template 2 moves to rectangle 1. And Template 3 moves to rectangle 2.

---

<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:** [July 24, 2020, 9:30pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/10 "2020-07-24T21:30:37Z")

</div>

Would be something like this - `rectangle` is the input component, `rectangle.parent` would have to be adjusted to be a reference to the root container.

```auto
from javax.swing import SwingUtilities
adjusted = SwingUtilities.convertPoint(rectangle, rectangle.X, rectangle.Y, rectangle.parent)
#use adjusted.X, adjusted.Y

```

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 24, 2020, 9:52pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/11 "2020-07-24T21:52:20Z")

</div>

```
from javax.swing import SwingUtilities

#Button constants.
t_Duration = 1000
t_Callback = None
t_FPS = 60
t_Accel = system.gui.ACCL_CONSTANT
t_Coord = system.gui.COORD_DESIGNER

#Initialize arrays of anchor points and templates on screen.
template = [0 for x in range(3)]

rectangle = event.source.parent

#Retrieve templates on screen.
template[0] = event.source.parent.getComponent('Template0')
template[1] = event.source.parent.getComponent('Template1')
template[2] = event.source.parent.getComponent('Template2')

adjusted0 = SwingUtilities.convertPoint(template[0], template[0].x, template[0].y, rectangle)
adjusted1 = SwingUtilities.convertPoint(template[1], template[1].x, template[1].y, rectangle)
adjusted2 = SwingUtilities.convertPoint(template[2], template[2].x, template[2].y, rectangle)

Animation.transformThis(template[1], adjusted1.x, adjusted1.y, template[1].width, template[1].height, t_Duration, t_Callback, t_FPS, t_Accel, t_Coord)

```

Well I assumed the above would keep the template[1] in the exact same location but it moved it slightly… Thoughts? If I figure this out I promise to leave you in peace for a week 😄

---

<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:** [July 24, 2020, 10:26pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/12 "2020-07-24T22:26:24Z")

</div>

If it’s only moving it slightly, it might be coordinates rounding down from floating point to integer, and there might not be a lot you can do about that - I think `convertPoint` only works with integer values.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 24, 2020, 10:29pm UTC](https://forum.inductiveautomation.com/t/solved-vision-animation-using-system-gui-movecomponent/37022/13 "2020-07-24T22:29:49Z")

</div>

😓 😭

Back to the alternative method I guess. Hope the team includes more coordinates support in version 9…
