Skip to content

Instantly share code, notes, and snippets.

@StepMaher
Last active November 4, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StepMaher/7fe310e7d8cc9cc2de0b to your computer and use it in GitHub Desktop.
Save StepMaher/7fe310e7d8cc9cc2de0b to your computer and use it in GitHub Desktop.
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