Eto Forms, Select object without closing the form

Hello,

I am working on an ETO form which supposed to chose objects but currently after closing the form I am able to chose objects. How can I make it enable to do it without closing the form?

"""Provides a scripting component.
    Inputs:
        x: The x script variable
        y: The y script variable
    Output:
        a: The a output variable"""

__author__ = "umut_"
__version__ = "2022.11.10"

# Imports
import Rhino
import scriptcontext
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import webbrowser

from Rhino.DocObjects import *
from Rhino.Commands import *
from Rhino.Input import *
from Rhino.Input.Custom import *
from scriptcontext import doc
import rhinoscriptsyntax as rs



 
# SampleEtoRoomNumber dialog class
class SampleEtoRoomNumberDialog(forms.Dialog[bool]):
    def OnLinkButtonClick(self, sender, e):
        webbrowser.open("https://www.ladybug.tools/epwmap/")
    # Dialog box Class initializer
    def __init__(self):
        # Initialize dialog box
        self.Title = 'Site Analysis Tool'
        self.Padding = drawing.Padding(10)
        self.Resizable = True
       
        # Create URL Button
        self.m_linkbutton = forms.LinkButton(Text = 'Select Location')
        self.m_linkbutton.Click += self.OnLinkButtonClick
 
        # Create Label for TextBox
        self.m_label = forms.Label(Text = 'Enter Location URL:')
        self.m_textbox = forms.TextBox(Text = None)
        
        #NumericUpDown
        self.m_numeric_updown = forms.NumericUpDown()
        self.m_numeric_updown.DecimalPlaces = 2
        self.m_numeric_updown.Increment = 0.01
        self.m_numeric_updown.MaxValue = 10.0
        self.m_numeric_updown.MinValue = 1.0
        self.m_numeric_updown.Value = 5.0
        
        # Create a slider MONTH
        self.m_label_month = forms.Label()
        self.m_label_month.Text = "Select Month"
        self.m_label_slider_month = forms.Label()
        self.m_slider_month = forms.Slider()
        self.m_slider_month.MaxValue = 12
        self.m_slider_month.MinValue = 1
        self.m_slider_month.Value = 3
        self.m_slider_month.ValueChanged += self.OnSliderMonthChanged
        self.m_label_slider_month.Text = str(self.m_slider_month.Value)
        
        self.viewport0 = Rhino.UI.Controls.ViewportControl(Size = drawing.Size(400, 200))
        
        # Create a slider DAY
        self.m_label_day = forms.Label()
        self.m_label_day.Text = "Select Day"
        self.m_label_slider_day = forms.Label()
        self.m_slider_day = forms.Slider()
        self.m_slider_day.MaxValue = 31
        self.m_slider_day.MinValue = 1
        self.m_slider_day.Value = 3
        self.m_slider_day.ValueChanged += self.OnSliderDayChanged
        self.m_label_slider_day.Text = str(self.m_slider_day.Value)
        
        
        # Create Select Room button
        self.SelectRoom = forms.Button(Text = 'Select Room')
        self.SelectRoom.Click += self.OnSelectRoomButtonClick
        
        # Create Select Room button
        self.SelectWindows = forms.Button(Text = 'Select Windows')
        self.SelectWindows.Click += self.OnSelectWindowsButtonClick

        # Create the default button
        self.DefaultButton = forms.Button(Text = 'OK')
        self.DefaultButton.Click += self.OnOKButtonClick
 
        # Create the abort button
        self.AbortButton = forms.Button(Text = 'Cancel')
        self.AbortButton.Click += self.OnCloseButtonClick
 
        # Create a table layout and add all the controls
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(self.m_linkbutton)
        layout.AddRow(self.m_label, self.m_textbox)
        layout.AddRow(self.m_numeric_updown)
        layout.AddRow(self.m_label_month)
        layout.AddRow(self.m_slider_month , self.m_label_slider_month)
        layout.AddRow(self.m_label_day)
        layout.AddRow(self.m_slider_day , self.m_label_slider_day)
        layout.AddRow(self.SelectRoom)
        layout.AddRow(self.SelectWindows)
        layout.AddRow(self.viewport0)
        layout.AddRow(None) # spacer
        layout.AddRow(self.DefaultButton, self.AbortButton)
 
        # Set the dialog content
        self.Content = layout
 
    # Start of the class functions
 
    # Get the value of the textbox
    def GetText(self):
        return self.m_textbox.Text
    def GetNumber(self):
        return self.m_numeric_updown.Value
    #To get selected slider value
    def GetSliderMonthValue(self):
        return self.m_slider_month.Value
    def GetSliderDayValue(self):
        return self.m_slider_day.Value
    #To show selected slider value
    def OnSliderMonthChanged(self, sender, e):
        self.m_label_slider_month.Text = str(self.m_slider_month.Value)
    def OnSliderDayChanged(self, sender, e):
        self.m_label_slider_day.Text = str(self.m_slider_day.Value)
    # Select Room button click handler
    def OnSelectRoomButtonClick(self, sender, e):
        rc, obj_ref = RhinoGet.GetOneObject("Select object", False, ObjectType.Brep)
        if rc != Result.Success:
            return rc
        brep = obj_ref.Brep()
        return Rhino.Commands.Result.Success
        rs.UnselectAllObjects()
    # Select Room button click handler
    def OnSelectWindowsButtonClick(self, sender, e):
        rc, obj_ref = RhinoGet.GetOneObject("Select object", False, ObjectType.Brep)
        if rc != Result.Success:
            return rc
        brep2 = obj_ref.Brep()
        return Rhino.Commands.Result.Success
        rs.UnselectAllObjects()

    # Close button click handler
    def OnCloseButtonClick(self, sender, e):
        self.m_textbox.Text = ""
        self.Close(False)
 
    # OK button click handler
    def OnOKButtonClick(self, sender, e):
        if self.m_textbox.Text == "":
            self.Close(False)
        else:
            self.Close(False)
 
    ## End of Dialog Class ##
 
# The script that will be using the dialog.
def RequestRoomNumber():
    dialog = SampleEtoRoomNumberDialog();
    rc = dialog.ShowModalAsync(Rhino.UI.RhinoEtoApp.MainWindow)
    if (rc):
        return dialog.GetText() , dialog.GetNumber(), dialog.GetSliderMonthValue(), dialog.GetSliderDayValue(), brep, brep2



##########################################################################
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.

#returning all the values
if x == True:
    if __name__ == "__main__":
        result = RequestRoomNumber()
        epw_link = result[0]
        number = result[1]
        month = result[2]
        day = result[3]
        brep = result[4]
        brep2 = result[5]
[SiteAnalysisTest.gh|attachment](upload://b40ML9nKoSk9Rm0HcXtN3D04VsR.gh) (12.4 KB)

SiteAnalysisTest.gh (12.4 KB)

Hi @Umut_Can_Kizilray,

Rhino.UI has a PushPickButton extension method that will allow you to pick objects from a model Eto form.

I’ve attached a sample for you to review.

test_pushpickbutton.py (1.7 KB)

– Dale

1 Like