@carlo1 wrote:
Hi everyone
so im looking to make my ETO form update when the user changes something about the input data
in this example, I would like mutiple things to update the eto form in real time:
when i hit the purge button, I have that bound to a method that purges the layers, obviously. but i also have the number of rows on the dynamic eto layout conform to the number of layers i have. whats happening is the button is purging the layers but the eto form doesnt update
I have a row for when the user is feeling lazy and doesnt want to asign objects to a layer but i also have a button that would ideally add another row of laziness. the way i have this in code is that all buttons and the number of rows is associated to a variable that is an interger and when the add select line is clicked, it adds 1 to that varible (it starts at 1 but when i manually chage it to 2 it works and there are 2 ‘select’ rows.
sorry about the essay, i hope this makes sense, im quite new to scripting and i only starting reading up about ETO forms 2 days ago so any help will be massivley apreciated.
is this possible? i would be happy with closing and opening the eto form everytime the eto form needs to be updated. my code is below. Thank you massivley in advance!
P.S. if you see anything in my code that is just bad in general, please let me know im still learning
import rhinoscriptsyntax as rs import Rhino.UI import Eto.Drawing as drawing import Eto.Forms as forms class Material_assigner(forms.Dialog[bool]): def __init__(self, material_names):##setting up the eto form self.Title = "Material Assigner" self.Padding = drawing.Padding(10) self.Resizable = False self.layer_names = rs.LayerNames() ### normal layer controls self.checkboxes = [] for i in self.layer_names: checkbox = forms.CheckBox( Text = "") ##check boxes (always true to assume u want to calculate every layer checkbox.Checked = True self.checkboxes.append(checkbox) self.dropdowns = [] for i in self.layer_names: dropdown = forms.ComboBox() ##dropdown menu you can edit dropdown.DataStore = material_names dropdown.SelectedIndex = 0 self.dropdowns.append(dropdown) self.DefaultButton = forms.Button(Text = 'OK') self.DefaultButton.Click += self.OnOKButtonClick self.AbortButton = forms.Button(Text = 'Cancel') self.AbortButton.Click += self.OnCloseButtonClick self.addselectbutton = forms.Button(Text = 'Add select line') self.addselectbutton.Click += self.addselectlevel self.purgelayersbutton = forms.Button(Text = 'Purge Layers') self.purgelayersbutton.Click += self.purgeclick ###changing number of selecting options controls self.number_select_button_rows = 1 ##to increase by one every time the user chooses self.selectbuttons= [] for i in range(self.number_select_button_rows): selectbutton = forms.Button(Text = "Select / Im Lazy") selectbutton.Click += self.OnSelectButtonClick self.selectbuttons.append(selectbutton) self.selectcheckboxes = [] for i in range(self.number_select_button_rows): checkboxselect = forms.CheckBox( Text = "") checkboxselect.Checked = True self.selectcheckboxes.append(checkboxselect) self.selectdropdowns=[] for i in range(self.number_select_button_rows): dropdownselect = forms.ComboBox( Text ="") dropdownselect.DataStore = material_names dropdownselect.SelectedIndex = 0 self.selectdropdowns.append(dropdownselect) ## Layout### layout = forms.DynamicLayout() layout.Spacing = drawing.Size(5,5) for index, layer in enumerate(self.layer_names): layout.AddRow(self.checkboxes[index], layer, self.dropdowns[index])#u can just chuck strings in layouts and it acts like a lable layout.AddRow(None) layout.AddRow(None) for i in range(self.number_select_button_rows): layout.AddRow(self.selectcheckboxes[i], self.selectbuttons[i], self.selectdropdowns[i]) layout.AddRow(None) layout.AddRow(None, self.purgelayersbutton, self.addselectbutton) layout.AddRow(self.DefaultButton, self.AbortButton) self.Content = layout ###operating methods def getobjectids(self): rs.Command('SelAll') check_ids = rs.GetObjects( preselect = True) solids_or_surf = [] for id in check_ids: if rs.IsCurve(id) == True: return None else: rs.Command('SelAll') rs.Command('Cap') rs.Command('SelNone') rs.Command('SelClosedPolysrf') object_ids = rs.GetObjects(filter = 16, preselect=True) return object_ids def layervolume(self, ids): layervolume = {} if ids == None: layervolume[ids] = 'unable to calculate volume' return layervolume else: for id in ids: if rs.SurfaceVolume(id) != None: layervolume[rs.ObjectLayer(id)] = sum(rs.SurfaceVolume(id)) * 0.000000001 else: layervolume['something strange'] = 'unable to calculate volume' return layervolume def checkboxchecks(self): checkboxchecked_index =[] for index, checkbox in enumerate(self.checkboxes): if checkbox.Checked == True: checkboxchecked_index.append(index) return checkboxchecked_index def materials_selected(self): materials_selected_index = [] for dropdown in self.dropdowns: materials_selected_index.append(dropdown.SelectedIndex) return materials_selected_index def activate(self): checked_boxes_index = self.checkboxchecks() materials_index = self.materials_selected() data = self.layervolume(self.getobjectids()) return data ### Button methods def OnOKButtonClick(self, sender, e): self.Close(True) try: print(self.activate()) except: print("error! no objects found") def purgeclick(self, sender, e): for layer in self.layer_names: if rs.IsLayerEmpty(layer) == True: rs.DeleteLayer(layer) def OnCloseButtonClick(self, sender, e): self.Close(False) def OnSelectButtonClick(self, sender, e): return True def addselectlevel(self, sender, e): self.number_select_button_rows = self.number_select_button_rows + 1 def OnSelectButtonAddClick(self, sender, e): pass ##script def test(materials): test = Material_assigner(materials); rhinowindow = test.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow) print(test.number_select_button_rows) test(["material 1", "material 2", "material 3"])
Posts: 1
Participants: 1