Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get X and Y dimensions of all screens. Note: This works once per GH instance.
"""
Get X and Y dimensions of all screens. Note: This works once per GH instance.
Outputs:
Rights: Width.
Bottoms: Height.
Names: Monitor displays.
"""
# Name component
ghenv.Component.Name = "Get All Screen Dimensions"
ghenv.Component.NickName = 'Get Screens'
# Import libraries
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Screen
import System.Windows.Forms
# Create output lists
Rights = []
Bottoms = []
Names = []
# Access screen dimensions and add to output lists
screens = Screen.AllScreens
for screen in screens:
control = System.Windows.Forms.Control()
graphics = control.CreateGraphics()
mult = (float(graphics.DpiX) / 96)
Rights.append(screen.Bounds.Right / mult)
Bottoms.append(screen.Bounds.Bottom / mult)
Names.append(str(screen.DeviceName))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.