Hi
I have just started to learn Python and have created a small Ui to select between import and export and a drop down list to select the file format to work with.
How do I create the options that if import and SC4W is selected then codeA is run, if import and Tritop are selected then codeB is run etc.
The actual Rhino functions in Python are quite straight forward but combining forms and an interface to give choices is where I find the info slightly lacking so all help appreciated.
# Imports
import Rhino
import scriptcontext
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs
# ImportExportPoints dialog class
class ImportExportPointsDialog(forms.Dialog[bool]):
# Dialog box Class initializer
def __init__(self):
# Initialize dialog box
self.Title = "Import Export Points"
self.Padding = drawing.Padding(10)
self.Resizable = False
# Create controls for the dialog
self.m_import_checkbox = forms.CheckBox(Text = 'Select if import points')
self.m_import_checkbox.Checked = True
self.m_export_checkbox = forms.CheckBox(Text = 'Select if export points')
self.m_combobox = forms.ComboBox()
self.m_combobox.DataStore = ['SC4W', 'Tritop', 'Excel']
self.m_combobox.SelectedIndex = 0
self.m_label = forms.Label(Text = 'Select Format:')
# 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_import_checkbox)
layout.AddRow(self.m_export_checkbox)
layout.AddRow(self.m_label, self.m_combobox)
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 first checkbox
def GetImport(self):
return self.m_import_checkbox.Checked
# Get the value of the first checkbox
def GetExport(self):
return self.m_export_text_box.Checked
def GetFormatOption(self):
return self.m_combobox.SelectedIndex
# Close button click handler
def OnCloseButtonClick(self, sender, e):
self.Close(False)
# OK button click handler
def OnOKButtonClick(self, sender, e):
self.Close(True)
## End of Dialog Class ##
def rogerScript(Import, Export, FormatOption):
# So we got 3 params: the first 2 are self explanatory
# And the third one is the format option: 0 = SC4W, 1 = Tritop, 2 = Excel