# Find component x y in an expression

**URL:** <https://forum.inductiveautomation.com/t/find-component-x-y-in-an-expression/8002>\
**Category:** Ignition\
**Created:** [February 13, 2014, 8:33pm UTC](https://forum.inductiveautomation.com/t/find-component-x-y-in-an-expression/8002 "2014-02-13T20:33:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cja7928](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@cja7928](https://forum.inductiveautomation.com/u/cja7928)\
**Post date:** [February 13, 2014, 8:33pm UTC](https://forum.inductiveautomation.com/t/find-component-x-y-in-an-expression/8002/1 "2014-02-13T20:33:50Z")

</div>

is there a way to find the X,Y position of a template through a property expression?

something like [quote]{Root Container.mytemplate.getX()}[/quote]

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [February 13, 2014, 9:00pm UTC](https://forum.inductiveautomation.com/t/find-component-x-y-in-an-expression/8002/2 "2014-02-13T21:00:00Z")

</div>

You could put a custom property on your template or component that contains your Y or X value. Then reference that property in your expression.

Or you could use the runScript expression function to call a Python function that gets the X and Y values of a particular component.

---

<div class="post-metadata">

**Author:** ![cja7928](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@cja7928](https://forum.inductiveautomation.com/u/cja7928)\
**Post date:** [February 13, 2014, 9:04pm UTC](https://forum.inductiveautomation.com/t/find-component-x-y-in-an-expression/8002/3 "2014-02-13T21:04:25Z")

</div>

thats the problem - the expression im looking to make is for a template property so I can reference that templates position. I have a whole bunch of this template to create instances for and need to know where each one is without putting it in manually. if the property was a script rather than an expression I would just use event.source.parent.getX(). im just not sure how to use an expression to find the X and Y

thanks.

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [April 27, 2015, 6:28pm UTC](https://forum.inductiveautomation.com/t/find-component-x-y-in-an-expression/8002/4 "2015-04-27T18:28:23Z")

</div>

You can get the X and Y position of a component from within an expression with the following examples

[code]runScript(“system.gui.getWindow(‘Test’).getRootContainer().getComponent(‘Momentary Button’).getX()”, 250)

runScript(“system.gui.getWindow(‘Test’).getRootContainer().getComponent(‘Momentary Button’).getY()”, 250)[/code]

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [July 27, 2020, 5:13pm UTC](https://forum.inductiveautomation.com/t/find-component-x-y-in-an-expression/8002/5 "2020-07-27T17:13:18Z")

</div>

To get a reference to a component for an expression with no event object, replace `event.source` with `self`:

```java
runScript("self.getX()", 250)

```

Within a template, you’ll probably want a parent in there to get the template holder’s position, something like:

```java
runScript("self.parent.getX()", 250)

```
