Get Screen Size

Hi,

I was search around looking for a way to capture the size of the screen using python and found this link:
[https://developer.rhino3d.com/api/rhinoscript/utility_methods/getsystemmetrics.htm]

I cannot seem to locate this in the help files for Rhinoscript? I’ve used this Windows Function in VBA for many years but cannot determine how to do this in Python.

In VBA I would access it this way:

Private Declare PtrSafe Function GetSystemMetrics32 Lib “user32” Alias “GetSystemMetrics” ( _
ByVal nIndex As LongPtr) As LongPtr

Private Sub GetWindowSize(lngWidth As LongPtr, lngHeight As LongPtr)

Set swApp = Application.SldWorks
swApp.Visible = True
swApp.UserControl = True

lngWidth = GetSystemMetrics32(0) ' width in points
lngHeight = GetSystemMetrics32(1) ' height in points

End Sub

Any help would be greatly appreciated.

Eric


import ctypes
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)

1 Like

Fantastic. Thank you so much.

Eric

Follow up to last question:

Looking for the dpi of screen as well. Any idea on how to implement this: GetDpiForWindow
I’m looking for the pixel density of the monitor.

Eric

Hi Eric,

I bet the answer you seek is in the link I provided.

I found this example:

I was able to construct it this way, thanks:

from ctypes import *

CreateDC = windll.gdi32.CreateDCA
GetDeviceCaps = windll.gdi32.GetDeviceCaps

NULL = c_int(0)
HORZRES = c_int(8)
VERTRES = c_int(10)
LOGPIXELSX = 88
POINTS_PER_INCH = 72

screen = CreateDC(c_char_p(“DISPLAY”),NULL,NULL,NULL)
x = GetDeviceCaps(screen,HORZRES)
y = GetDeviceCaps(screen,VERTRES)
lDotsPerInch = GetDeviceCaps(screen,LOGPIXELSX)
PointsPerPixel = POINTS_PER_INCH / lDotsPerInch

print(x,y,PointsPerPixel)

What a creepy syntax lol

1 Like

Yes it is. Lol. Thanks for steering me in the right direction.

If by chance you are working on an 1:1 setting then Rhino has a calibration tool for that.

What I was trying to is open Excel and tile it next to Rhino. I have a high res touch screen monitor with a standard external 2nd monitor. It is a scaling issue with the laptop monitor. I solved it in VBA using Windows Api routines
that checked the pixel density of the laptop. It was a way to get two programs (at the time Solidworks and Excel) to take up a defined percentage of the screen.

In this case I want to determine my monitor resolution and pixel density and through formulas tile Excel on one side and Rhino on the other. Could be 50:50 or some other percentage. If there is an easier way to do this I’m all
for it. So far I have been successful opening and sizing Excel. I have yet to determine how to do this with Rhino.

Eric

OK, sounds smart.
For my needs the built in Windows10 "drag one app/programs to the side-edge of the monitor and then it automatically fills up 50% and then I choose what other software to fill the other 50% "- thing does the trick.
:slight_smile:

Thanks!!