Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

How can i use the variables entered at eto window in another code

$
0
0

Hello I haven’t been programming for long and would like to use an entry in an eto window for another code, can someone help me. Thank you :slight_smile:
I mean how can i use the Variable which entered here: self.m_textbox = forms.TextBox(Text = None)
I just use the code from this site.

Imports

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

SampleEtoRoomNumber dialog class

class SampleEtoRoomNumberDialog(forms.Dialog[bool]):

# Dialog box Class initializer
def __init__(self):
    # Initialize dialog box
    self.Title = 'Sample Eto: Room Number'
    self.Padding = drawing.Padding(10)
    self.Resizable = False

    # Create controls for the dialog
    self.m_label = forms.Label(Text = 'Enter the Room Number:')
    self.m_textbox = forms.TextBox(Text = None)

    # 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_label, self.m_textbox)
    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

# 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(True)

## End of Dialog Class ##

The script that will be using the dialog.

def RequestRoomNumber():
dialog = SampleEtoRoomNumberDialog();
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if (rc):
print dialog.GetText() #Print the Room Number from the dialog control

##########################################################################

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.

if name == “main”:
RequestRoomNumber()

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles