# -*- coding: utf-8 -*-
import Eto as e
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
command_name = ''
# button color
default_color = e.Drawing.Color(0, 0, 0, 0)
color_a = e.Drawing.Color(0.682353, 0.772549, 0.901961)
color_b = e.Drawing.Color(0.54902, 0.870588, 0.760784)
color_exit = e.Drawing.Color(0.921569, 0.882353, 0.486275)
prev_color = e.Drawing.Color(0.921569, 0.513725, 0.513725)
# button dict list
column_dict_list = [[{'text': '锁 定', 'cmd': '_Lock', 'color': color_a},
{'text': '解锁选取', 'cmd': '_UnlockSelected', 'color': default_color},
{'text': '解 锁', 'cmd': '_Unlock', 'color': default_color}],
[{'text': '曲面上曲线', 'cmd': '_InterpcrvOnSrf', 'color': color_b},
{'text': '单 轨', 'cmd': '_Sweep1', 'color': default_color},
{'text': '双 轨', 'cmd': '_Sweep2', 'color': default_color},
{'text': '退 出', 'cmd': 'exit', 'color': color_exit}]]
class CustomDialog(e.Forms.Dialog):
def __init__(self):
def define_button(_i, _j):
item = column_dict_list[_i][_j]
btn = e.Forms.Button(Text=item['text'], Height=25, ID=item['cmd'], BackgroundColor=item['color'],
click=OnButtonPress)
return btn
def OnButtonPress(sender, e):
global command_name # global variable
command_name = sender.ID # ID = command name
sc.sticky['prev'] = command_name # record command name to rhino sticky
self.Close() # close ETO dialog
# ETO layout
layout = e.Forms.DynamicLayout()
layout.BeginHorizontal()
for i in range(len(column_dict_list)):
layout.BeginVertical()
for j in range(len(column_dict_list[i])):
layout.Add(define_button(i, j))
layout.EndVertical()
self.Content = layout
# load previous button
if 'prev' in sc.sticky:
prev_command = sc.sticky['prev'] # load recorded command name
last_button = layout.FindChild(prev_command) # find the button
last_button.BackgroundColor = prev_color # change background color
last_button.Focus() # set focus to button
dialog = CustomDialog()
# load previous dialog position
if 'pos' in sc.sticky:
dialog.Location = sc.sticky['pos']
dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if command_name != 'exit':
rs.Command(command_name)
# record current dialog position
sc.sticky['pos'] = dialog.Location
1 Like