Solved

Get Window Size (H x W)

  • 11 December 2023
  • 5 replies
  • 175 views

Userlevel 3
Badge +9

Anyone know of a way to get the window height and width in pixels in Automation Anywhere?

I want to get the size of a window during runtime and then assign the height and the width to variable so I can resize subsequent windows with the dimensions.

icon

Best answer by Abhay Naik 11 December 2023, 16:33

View original

5 replies

Userlevel 3
Badge +7

Hey @LoganPrice ,

There is no inbuilt command as far as I know which will give you a window dimensions. But, you can try one way, Using recorder or AI sense see if that window entirely gets recognized as a object. This way object property will have the height, width etc. This then you can use for your further processing. For sure this will be little tricky and may slow down the bot run time. 

 

Let me also see if I can provide you some scripts which can give you the desired results. To Resize any window may be you have figured it out, There is a command called Resize, this should resize your windows.

Userlevel 3
Badge +9

Thanks @Abhay Naik!

Your recommendation to capture the height and width from the window via recorder worked like a charm!

So simple - thanks again!

 

Userlevel 3
Badge +7

Hi @LoganPrice ,

Great! happy that i was able to help. 

But, this method may not be a reliable one. You may have to test it in you runner machines for reliability. Wonder if it will ask you to re-record if you change the machine. Here is the the python script for you which i feel is reliable and can be used anywhere and on any window. You need to provide the Active Windows Title as an input and the script will give you the dimensions.

 

import pygetwindow as gw

def get_window_size(window_title):
    try:
        window = gw.getWindowsWithTitle(window_title)[0]
        width, height = window.size
        return width, height
    except IndexError:
        return None  # Window not found

# Example usage
window_title = "Enter the windows Title"
window_size = get_window_size(window_title)

if window_size is not None:
    print(f"Size of window '{window_title}': {window_size[0]} x {window_size[1]} pixels")
else:
    print(f"Window '{window_title}' not found.")

 

Userlevel 3
Badge +9

Thanks for the script @Abhay Naik - unfortunately, our runners are not set up with Python so we are unable to use scripts.

Userlevel 3
Badge +7

Hi @LoganPrice,

For sure we can achieve the same using the VBScript. Only thing is, I guess VBScript support is going to get deprecated by Microsoft. So long term feasibility is a challenge.

Reply