Hi all.
I want to select a bunch of Rhino objects when i click on the “Select objects” button, then I want the dialog form to come back before I click on the “Export” button. The export button will then export the selected objects with the settings from the dialog form (this part is still WIP)
the code below gives a forms.dialog like this:
but at the moment i can’t get the dialog window to come back before i click on “Export”
any help will be thanked!
# URL: https://discourse.mcneel.com/t/hide-and-show-form-with-eto-python-script-help-me/70920
import Rhino
import scriptcontext as sc
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs
objs = [] # don't know if i can remove this declaration at global level?
def GetRhinoObjects():
#get objects from Rhino by user input
objs = rs.GetObjects('Select objects to export')
if not objs: return
return objs
# sort selected objects by layer name
def SortObjByLayer():
objs = GetObjects()
objLayerNames = []
if objs:
for obj in objs:
objLayerNames.append(rs.ObjectLayer(obj))
objLayerName = sorted(set(objLayerNames))
for i in objLayerName:
#print i
selectedObjByLayer = []
layerObjs = rs.ObjectsByLayer(i)
for obj in objs:
if obj in layerObjs:
#print obj
selectedObjByLayer.append(obj)
#print i
#print selectedObjByLayer
# testing by grouping
"""
rs.UnselectAllObjects()
rs.SelectObjects(selectedObjByLayer)
rs.Command("_-Group Enter")
rs.UnselectAllObjects()
"""
# export object by setting - WIP
def ExportObjects(objs, ext, oPt, path):
if oPt == 0:
expPt = '0,0,0'
elif oPt == 1:
return
for obj in objs:
return
# dialog class
class EtoDialog(forms.Dialog[bool]):
#dialog box class initialiser
def __init__(self):
# initialise dialog box
self.Title = 'Export Selection As... '
self.Padding = drawing.Padding(10,5,5,5)
self.Resizalbe = False
# add radio buttons for export format selection
self.radioButtonList_ExpFormat = forms.RadioButtonList()
self.radioButtonList_ExpFormat.DataStore = ['3dm', 'dwg', 'dxf', 'stp']
#self.radioButtonList_ExpFormat.Orientation = forms.Orientation.Vertical
self.radioButtonList_ExpFormat.Orientation = forms.Orientation.Horizontal
self.radioButtonList_ExpFormat.SelectedIndex = 0
self.radioButtonList_ExpFormat.Spacing = drawing.Size(28, 5)
self.radioButtonList_ExpFormat.Padding = drawing.Padding(10, 5, 5, 5)
# add radio buttons for export origin point
self.radioButtonList_ExpOrigin = forms.RadioButtonList()
self.radioButtonList_ExpOrigin.DataStore = ['World', 'Object Center']
#self.radioButtonList_ExpOrigin.Orientation = forms.Orientation.Vertical
self.radioButtonList_ExpOrigin.Orientation = forms.Orientation.Horizontal
self.radioButtonList_ExpOrigin.SelectedIndex = 0
self.radioButtonList_ExpOrigin.Spacing = drawing.Size(20, 5)
self.radioButtonList_ExpOrigin.Padding = drawing.Padding(10, 5, 5, 5)
# add radio buttons for export setting
self.radioButtonList_ExpGroup = forms.RadioButtonList()
self.radioButtonList_ExpGroup.DataStore = ['by object name', 'by layer name']
#self.radioButtonList_ExpGroup.Orientation = forms.Orientation.Vertical
self.radioButtonList_ExpGroup.Orientation = forms.Orientation.Horizontal
self.radioButtonList_ExpGroup.SelectedIndex = 0
self.radioButtonList_ExpGroup.Spacing = drawing.Size(20, 5)
self.radioButtonList_ExpGroup.Padding = drawing.Padding(10, 5, 5, 5)
# create controls
# self.m_image1 = forms.ImageView(Image = drawing.Bitmap(imagePath))
self.label_ExpFormat = forms.Label(Text = "Format: ")
self.label_ExpOrigin = forms.Label(Text = "Origin: ")
self.label_ExpGroup = forms.Label(Text = "Naming: ")
self.label_Prefix = forms.Label(Text = "Prefix", Width = 80)
self.label_Path = forms.Label(Text = "Export to: ", Width = 80)
# create text box
self.textbox_Prefix = forms.TextBox(Text = "-", Width = 150)
self.textbox_Path = forms.TextBox(Text = stickyval, Width = 400)
# create default button
self.DefaultButton = forms.Button(Text = 'Export')
self.DefaultButton.Click += self.OnOKButtonClick
# create abort button
self.AbortButton = forms.Button(Text = 'Cancel')
self.AbortButton.Click += self.OnCloseButtonClick
# create pick button
self.SelectObjButton = forms.Button(Text = 'Select objects... ')
self.SelectObjButton.Click += self.SelectObjButtonClick
# create browse button
self.BrowseButton = forms.Button(Text = "Location")
self.BrowseButton.Click += self.OnBrowseButtonClick
# create table layout and add all the controls
layout = forms.DynamicLayout()
layout.Spacing = drawing.Size(5, 5)
layout.DefaultSpacing = drawing.Size(5,5)
# layout.AddRow(self.m_image1)
layout.AddSeparateRow(padding = 5)
layout.BeginVertical()
layout.AddRow(self.label_ExpFormat, self.radioButtonList_ExpFormat)
layout.AddRow(self.label_ExpOrigin, self.radioButtonList_ExpOrigin)
layout.AddRow(self.label_ExpGroup, self.radioButtonList_ExpGroup)
layout.EndVertical()
layout.AddSeparateRow(padding = 5)
layout.BeginVertical()
layout.AddRow(self.label_Prefix, self.textbox_Prefix, None)
layout.EndVertical()
layout.BeginVertical()
layout.AddRow(self.label_Path, self.textbox_Path, None)
layout.EndVertical()
layout.AddSeparateRow(padding = 5)
layout.BeginVertical()
layout.AddRow(None, self.SelectObjButton, self.BrowseButton, self.DefaultButton, self.AbortButton)
layout.EndVertical()
#set the dialog content
self.Content = layout
### START OF CLASS FUNCTIONS ###
# get value of the text box
def GetExpFormat(self):
return self.radioButtonList_ExpFormat.SelectedIndex
def GetExpExt(self):
return self.radioButtonList_ExpFormat.SelectedValue
def GetExpOrigin(self):
return self.radioButtonList_ExpOrigin.SelectedIndex
#return self.radioButtonList_ExpOrigin.SelectedValue
def GetExpGroup(self):
return self.radioButtonList_ExpOrigin.SelectedIndex
#return self.radioButtonList_ExpGroup.SelectedValue
# close button click handler
def OnCloseButtonClick(self, sender, e):
self.Close(False)
# OK button click handler
def OnOKButtonClick(self, sender, e):
self.Close(True)
# selection button click handler
def SelectObjButtonClick(self, sender, e):
self.Close(True)
objs.append(GetRhinoObjects())
def OnBrowseButtonClick(self, sender, e):
ExpPath = rs.BrowseForFolder(message='Export folder location')
self.textbox_Path.Text = ExpPath
return ExpPath
def GetExpPath(self):
return self.textbox_Path.Text
### END OF CLASS FUNCTIONS ###
def RunDialog():
dialog = EtoDialog()
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if (rc):
# getting export format selection index
ExpFormatIndex = dialog.GetExpFormat()
print ExpFormatIndex
# getting export format extension
ExpFormatExt = dialog.GetExpExt()
print ExpFormatExt
# getting export origin selection index
ExpOriginIndex = dialog.GetExpOrigin()
print ExpOriginIndex
# getting export grouping selection index
ExpGroupIndex = dialog.GetExpGroup()
print ExpGroupIndex
# getting export save folder
ExpFolder = dialog.GetExpPath()
print ExpFolder
# getting selected objects
if objs:
for obj in objs:
print obj
if not objs:
print "i got no thing"
stickyval = ExpFolder
sc.sticky["my_key"] = stickyval
#objs = SortObjByLayer()
#print ExpFormatExt, ExpOriginIndex, ExpGroupIndex
#print ExpFolder
#print objs
"""
for i in objs:
print objs
"""
if __name__ == '__main__':
# set sticky key for export folder
stickyval = "-"
# restore stickyval if it has been saved
if sc.sticky.has_key("my_key"):
stickyval = sc.sticky["my_key"]
"""
if rs.IsDocumentUserText():
projectID = rs.GetDocumentUserText("_Project_Number")
#print projectID
"""
RunDialog()