Open form in Rhino centered on current working screen

Hello everybody, I am very new in programming and sure that my question is a little bit silly…

I have found this information about how to show a form using python scripting:

Link
Forum post

Everything works ok, but the form is shown in the same screen that rhino started, but if I swap between my 2 screens (that happens very often), it is a little anoying to find where the form is.

Is it possible to force the opening centered on the current working screen?

Thank you!

Hi @Vicente_Durá,

if you use a Eto.Forms.Dialog in IronPython it automatically follows the position of the Rhino main window and opens centered on the same screen as Rhino:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
import Eto
class SampleEtoDialog(Eto.Forms.Dialog[bool]):
    def __init__(self):
        self.Title = "Title"
        self.Padding = Eto.Drawing.Padding(10)
        self.Size = Eto.Drawing.Size(200, 120)
        self.label = Eto.Forms.Label(Text="Hello World")
        self.DefaultButton = Eto.Forms.Button(Text = 'OK')
        self.DefaultButton.Click += self.OnOKButtonClick
        layout = Eto.Forms.DynamicLayout()
        layout.Spacing = Eto.Drawing.Size(5, 5)
        layout.AddRow(self.label)
        layout.AddRow(None)
        layout.AddRow(self.DefaultButton)
        self.Content = layout

    def OnOKButtonClick(self, sender, e):
        self.Close(True)

def DoSomething():
    dialog = SampleEtoDialog()
    rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
    
DoSomething()

Alternatively you could set the position manually to a position relative to Rhino’s main window. But thats more work.
_
c.

1 Like

Hi @clement , is there a method for this that you know of?

I’m using this code to place my form at the bottom center of the Rhino Window but this fails on Dual Monitors of course as this method is getting the Main display but not necessarily the Rhino Document screen.

        s = Rhino.UI.RhinoEtoApp.MainWindow.Screen     
        w = s.WorkingArea.Width 
        h = s.WorkingArea.Height

        self.Location = Eto.Drawing.Point((w / 2 - (self.Width / 2)), (h - self.Height + padding)) # Locate Form At Bottom Center Of Screen

I was intrigued about your Dialog statement but I’m doing some logic that (I think?) can only happen with a Form so I’m going that route.

Any ideas are appreciated, thank you!

Hi @michaelvollrath, just curious what do you get with below example script if:

  1. Rhino is maximized on the first screen
  2. Rhino is maximized on the second screen
  3. Rhino is not maximized but restored on one of the screens
  4. Rhino is not maximized but restored across both screens

Not sure if this works right for me in all situations, expecially the bottom alignment is way off when Rhino is not maximized. @dale could you enlighten us please ?

ETO_SampleFormLocation.py (2.2 KB)

_
c.

1 Like

Hi @clement , yes it’s also off for me as well so I have tabled it for a moment as I work through other elements but I certainly will be curious to know

1 Like