Hi,
Is there a way to set the size and position of the Rhino Window using Rhinoscript or the Rhino API? I want to set the size to 50% with the left of the window at the screens center.
Thanks,
Eric
Hi,
Is there a way to set the size and position of the Rhino Window using Rhinoscript or the Rhino API? I want to set the size to 50% with the left of the window at the screens center.
Thanks,
Eric
Hi @dale,
for recording the Rhino application window i wanted to set the exact size but found no way to do so programmatically. For getting the size i’ve found:
Rhino.UI.RhinoEtoApp.MainWindow.Size
but it returns a Width and Height which is 16 too large under windows. Is there a different (crossplatform) method to set and get the MainWindow size ?
thanks,
c.
@JohnM - any ideas here?
I don’t know if this is helpful but here is the code I put together to address the original question in the thread.
Eric
import Rhino
import rhinoscriptsyntax as rs
from ctypes import *
def GetWorkArea():
"""Get working area for monitor. Returns Top,Bottom,Left,Right"""
import ctypes
SPI_GETWORKAREA=48
class RECT(ctypes.Structure):
_fields_ = [('left',ctypes.c_ulong),('top',ctypes.c_ulong),('right',ctypes.c_ulong),('bottom',ctypes.c_ulong)]
x = ctypes.windll.user32
r = RECT()
x.SystemParametersInfoA(SPI_GETWORKAREA,0,ctypes.byref(r),0)
retvals = [r.top,r.bottom,r.left,r.right]
#Calc Size of TaskBar##############################
size = rs.ScreenSize()#X,Y
tBar = size[1]-abs(retvals[1] - retvals[0])
return retvals,tBar
def PPP():
"""Gets the Screen Resolution and Pixel Density"""
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 = float(POINTS_PER_INCH) / float(lDotsPerInch)
return lDotsPerInch,x,y
def GetRect():
"""Gets the size of the Rhino Parent Window"""
import ctypes
from ctypes import wintypes
hwnd = Rhino.RhinoApp.MainWindowHandle()
rect = wintypes.RECT()
ctypes.windll.user32.GetWindowRect(hwnd, ctypes.byref(rect))
width = rect.right - rect.left
height = rect.bottom - rect.top
return rect.top,rect.bottom,rect.left,rect.right,width,height
def SetWindowPos(x=0,y=0,w=0,h=0,onTop=True):
"""Sets Window Position for Left and Top and Size of Window (width,height)"""
import rhinoscriptsyntax as rs
from ctypes import *
HWND_TOPMOST = c_int(-1)
HWND_NOTOPMOST = c_int(-2)
SWP_NOMOVE = 0x02
SWP_NOSIZE = 0x01
TOGGLE_HIDEWINDOW = 0x80
TOGGLE_UNHIDEWINDOW = 0x40
SetWindowPos = windll.user32.SetWindowPos
if onTop == True:
SetWindowPos(rs.WindowHandle(),HWND_TOPMOST, x, y, w, h, TOGGLE_UNHIDEWINDOW)
else:
SetWindowPos(rs.WindowHandle(),HWND_NOTOPMOST, x, y, w, h, TOGGLE_UNHIDEWINDOW)
def GetScreenScaling():
import ctypes
scaleFactor = float(ctypes.windll.shcore.GetScaleFactorForDevice(0)) / 100
return scaleFactor
rect = GetWorkArea()
print(rect)#retvals = [r.top,r.bottom,r.left,r.right],tbar
scl = GetScreenScaling()
print(rect[0][3] * .7)
ufw = int(600*scl);print ufw,rect[0][3]-ufw
#SetWindowPos(ufw,rect[0][0],1170,rect[0][1]-rect[0][0],True)#Left and Top and Size of Window (width,height)
SetWindowPos(ufw,rect[0][0],rect[0][3]-ufw,rect[0][1]-rect[0][0],True)#Left and Top and Size of Window (width,height)
#' Set form on top http://www.vbforums.com/showthread.php?588169-FAQ-s-OD-How-do-I-set-a-UserForm-to-be-the-TopMost-form-throughout-Windows
#Private Declare PtrSafe Function SetWindowPos Lib "user32" ( _
# ByVal hwnd As LongPtr, _
# ByVal hWndInsertAfter As LongPtr, _
# ByVal X As LongPtr, _
# ByVal y As LongPtr, _
# ByVal cx As LongPtr, _
# ByVal cy As LongPtr, _
# ByVal wFlags As Long) As LongPtr
#
#Private Const HWND_TOPMOST = -1
#Private Const HWND_NOTOPMOST = -2
#Private Const SWP_NOMOVE = &H2
#Private Const SWP_NOSIZE = &H1
#Private mlHwnd As LongPtr
#SetWindowPos mlHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Thank you @eric.bunn, i can get the first function GetWorkArea
to run on windows, but this line in GetScreenScaling
produces an error:
scaleFactor = float(ctypes.windll.shcore.GetScaleFactorForDevice(0)) / 100
Unfortunately all code fails on Mac for me so i still would still be interested in finding a crossplatform solution.
_
c.