# Move components problem

**URL:** <https://forum.inductiveautomation.com/t/move-components-problem/65009>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [October 10, 2022, 2:00pm UTC](https://forum.inductiveautomation.com/t/move-components-problem/65009 "2022-10-10T14:00:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![d.iannozzi](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@d.iannozzi](https://forum.inductiveautomation.com/u/d.iannozzi)\
**Post date:** [October 10, 2022, 2:00pm UTC](https://forum.inductiveautomation.com/t/move-components-problem/65009/1 "2022-10-10T14:00:30Z")

</div>

Hello guys,  
I have the following code binding to a slider object to move a component...it works fine.  
I wanted to implement the same logic using two buttons ; one that moves the component UP and one that moves it DOWN. I am running into a series of issues ; if i simply decrement the origY by -5 or +5 the object does not move by 5 pixels...(what am i doing wrong)  
Thanks and regards,  
Dominic

component = event.source.parent.getComponent("elev")  
origX = 26  
origY = 465

system.gui.transform(  
component, 26, origY-event.source.value,  
)

event.source.parent.getComponent('beltDX').relHeight=347-event.source.value  
event.source.parent.getComponent('beltSX').relHeight=347-event.source.value

event.source.parent.getComponent('labelY').text = str(origY)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 10, 2022, 2:11pm UTC](https://forum.inductiveautomation.com/t/move-components-problem/65009/2 "2022-10-10T14:11:13Z")

</div>

Did you use the exact same code on your buttons ?  
If not, show us the code that doesn't work, not the one that does.  
And enclose your code in triple backticks, like that:

> ```python  
> code goes here  
> ```

---

<div class="post-metadata">

**Author:** ![d.iannozzi](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@d.iannozzi](https://forum.inductiveautomation.com/u/d.iannozzi)\
**Post date:** [October 10, 2022, 2:19pm UTC](https://forum.inductiveautomation.com/t/move-components-problem/65009/3 "2022-10-10T14:19:29Z")

</div>

This is the code binding on mousePressed for the button UP ; in the button DOWN I simply add +5 in the dest variable and check that dest does not go beyond 465

```auto
move = True
component = event.source.parent.getComponent("elev")
dest = component.y - 5

if dest < 170:
	dest=170
	move = False

if move:
	system.gui.transform(
		component,
		26, dest
	)
	event.source.parent.getComponent('beltDX').relHeight=event.source.parent.getComponent('beltDX').relHeight-5
	event.source.parent.getComponent('beltSX').relHeight=event.source.parent.getComponent('beltSX').relHeight-5

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 11, 2022, 10:26am UTC](https://forum.inductiveautomation.com/t/move-components-problem/65009/4 "2022-10-11T10:26:58Z")

</div>

I think you'll find it's a screen size thing. 9 times out of 10, your client screen will be a different size, if only slightly, to what you developed it as. In that case, absolute 5px on a client might actually be different base on the scaling applied. You should look at using the designer coordinate space instead of the client coord space so that your fixed pixel values are scaled accordingly in the client (it's an arg you provide into the transform function)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 11, 2022, 10:38am UTC](https://forum.inductiveautomation.com/t/move-components-problem/65009/5 "2022-10-11T10:38:10Z")

</div>

So I'm not familiar with vision (I expect this to be vision), but I can suggest a simplification for your script:

```python
component = event.source.parent.getComponent("elev")
dest = component.y - 5

if dest >= 170:
	system.gui.transform(component, 26, dest)
	event.source.parent.getComponent('beltDX').relHeight -= 5
	event.source.parent.getComponent('beltSX').relHeight -= 5

```

Your first `if` statement doesn't actually do anything except for setting up the second `if` condition.  
You're assigning a value to `dest`, which will not be used since if entering this part of the code, `move` becomes false and the second `if` is not entered.  
So, might as well get rid of that first `if`, and reverse the condition to enter the second one.

---

<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:** [October 11, 2022, 12:14pm UTC](https://forum.inductiveautomation.com/t/move-components-problem/65009/6 "2022-10-11T12:14:48Z")

</div>

> [@d.iannozzi](#):
>
> `relHeight`

`relHeight` is not correct for movement. This is a size parameter. The movement parameters are `relX` for horizontal movement and `relY` for vertical movement
