How to know the position of a component from the sctript editor in vision

In vision, I need to know the x, y position of a component using the script editor to save it for future use, what function can I use?

I’m going to show you how you can dig down into the functions available on a component.

In designer open the window that has the components you want to look at.

Then open your script console (Tools->Script console)

Try the following -

win = system.gui.getWindow("TheWindowName")
rc = win.getRootContainer()

for component in rc.components:
    firstComponent = component
    break
print dir(firstComponent)

This will print out all the available methods and properties on the component. I just tested it with a label component and found that they have a .x and .y property so I could have done this after the initial script

print firstComponent.x
print firstComponent.y

and that prints out the x/y pixles of the placement of it.

Alternatively, manually, you can always right click a component and select Size/Position and it will give you the x/y as well.

1 Like

@pturmel wrote a script function that does this pretty conveniently. I don't use it much, so I don't know if it works with modern Ignition (8+), but it might be worth checking out.

3 Likes

Yea that’s a nice function. Doing dir directly is the quick/dirty way to see all methods/properties available on a python object. His is a more explicit about what is a method and what is a property which is definitely useful.

I think it does not work in the script console because it generates the error: Window Proof is not currently open.

even if the window that tells me is open.

It’s open in the designer at the time of running your script? Try copy and pasting the window path.

Also you can always right click the component and check size/position.

Iindeed, I put the path of the window wrong, thank you very much! it worked perfectly after correcting it

1 Like

So instructive, thank you very much for your help

Legend.

1 Like