Any idea why?
import math
import Rhino
import Rhino.UI
import scriptcontext as sc
import System.Guid as sg
import System.Drawing as sd
import Eto.Drawing as drawing
import Eto.Forms as forms
class LayoutPublish(forms.Dialog[bool]):
def __init__(self, width, height, button_names, button_count, max_row, col_count, bt_width, bt_height):
self.Title = "Pick Layouts to Publish"
self.ClientSize = drawing.Size(width, height)
self.Padding = drawing.Padding(5)
#self.Resizable = False
#Table Layout for vertical columns
layout = forms.TableLayout()
layout.Spacing = drawing.Size(5, 5) #Space between cells
layout.Padding = drawing.Padding(5) #Dialog padding
#Dictionary to store button states and button references
self.button_states = {button_names[i]: False for i in range(len(button_names))}
self.buttons = {}
#Create a row to hold columns of buttons
button_row = forms.TableRow()
#Create columns
button_index = 0
self.choice = None
for col in range(col_count):
#Create a vertical StackLayout for each column
column_layout = forms.StackLayout()
column_layout.Orientation = forms.Orientation.Vertical
column_layout.Spacing = 5
#column_layout.Width = bt_width + 10
#Add buttons to this column
for row in range(min(max_row, button_count - button_index)):
button_name = button_names[button_index]
button = forms.Button(Text = button_name)
button.Click += lambda sender, e, bt_nm = button_name: self.OnToggleButtonClick(sender, e, bt_nm)
self.buttons[button_name] = button
LayerButtonFormat(button, bt_width, bt_height)
column_layout.Items.Add(button)
button_index += 1
#Add the column to the row
cell = forms.TableCell(column_layout, True)
button_row.Cells.Add(cell)
layout.Rows.Add(button_row)
self.Content = layout #Set the dialog's content
def OnToggleButtonClick(self, sender, e, button_name):
# Toggle state
self.button_states[button_name] = not self.button_states[button_name]
# Update button appearance
button = self.buttons[button_name]
if self.button_states[button_name]:
button.Text = "*" + button.Text + "*"
button.BackgroundColor = drawing.Color.FromArgb(0, 150, 0)
else:
button.Text = button.Text[1:-1]
button.BackgroundColor = drawing.Color.FromArgb(50, 50, 50)
def OnKeyDown(self, e):
if e.Key == forms.Keys.Escape: self.Close(False)
if e.Key == forms.Keys.A: self.choice = "A"; self.Close(True)
if e.Key == forms.Keys.P: self.choice = "P"; self.Close(True)
def LayerButtonFormat(x, bt_width, bt_height):
x.Font = drawing.Font("ISOCPEUR", 20)
x.BackgroundColor = drawing.Color.FromArgb(50, 50, 50)
x.TextColor = drawing.Color.FromArgb(255, 255, 255)
x.Size = drawing.Size(bt_width, bt_height)#Fixed button size
return
def main():
layouts = sc.doc.Views.GetPageViews()
if not layouts:
print "\nNo layouts found.\nScript cancelled."; exit()
btn_count = len(layouts)
layout_names = [[l.PageName, l.PageNumber] for l in layouts]
layout_names = sorted(layout_names)
bt_width, bt_height = 100, 50
max_row = 7
col_count = int(math.ceil(float(btn_count) / max_row))
width = bt_width * col_count + 5 * (col_count - 1) + 30
height = bt_height * min(max_row, btn_count) + 5 * (min(max_row, btn_count) - 1) + 30
print width, height
dialog = LayoutPublish(width, height, [i[0] for i in layout_names], btn_count, max_row, col_count, bt_width, bt_height)
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if not rc: print "\nScript cancelled."; exit()
if dialog.choice == "P":
for i in layout_names:
if dialog.button_states[i[0]]: print i[0]
sc.doc.Objects.UnselectAll()
if __name__ == "__main__": main()
print "\nPrinting complete\n"
sc.doc.Views.RedrawEnabled = True