Hello, I am developing a python plug in for rhino using the Winforms UI, and recently made the switch from Rhino 5 to Rhino 6. When I am testing the UI in Rhino 6 and press a button that should cause an error, nothing happens. Previously in Rhino 5 this would return an error in the Rhino Python Editor.
I am running the UI using Rhino.UI.Dialogs.ShowSemiModal(my_winform_ui)
Does Winforms act differently in Rhino 6 vs Rhino 5, or is there a variable I should have on to allow errors to show up?
Let me know what other information I should provide if needed. Thanks!
Hi @BenFeicht, have you tried to catch errors in your code like below:
try:
# your code with errors
except Exception as ex:
print ex
Yes, on some functions i’ve seen different behaviour with WinForms in V6. V5 was not firing errors in delegates which now works in V6. You seem to see the opposite. It would be helpful to see some example code.
_
c.
Sorry for the delay. I tried the error catch mentioned but this did not work, although I may not be placing the lines mentioned in the right place.
I set up a sample WinForms code which has the same issue. In Rhino 5 an error is called, but in Rhino 6 and 7 the form just stops working.
import System.Drawing
import System.Windows.Forms
import rhinoscriptsyntax as rs
import Rhino
from System.Drawing import *
from System.Windows.Forms import *
def Main():
ui = TestUI()
Rhino.UI.Dialogs.ShowSemiModal(ui.form)
class UIForm(Form):
def __init__(self, title):
self.Text = title
self.panel = UIPanel()
self.Width = 10
self.Height = 10
def layoutControls(self):
self.AutoSize = True
self.ShowInTaskbar = True
self.MaximizeBox = False
self.MinimizeBox = True
self.ShowIcon = False
self.FormBorderStyle = FormBorderStyle.FixedToolWindow
self.SuspendLayout()
self.panel.layoutControls()
self.Controls.Add(self.panel)
ctrlList = self.panel.Controls.Find("Cancel", True)
if (len(ctrlList) != 0):
c = ctrlList[0]
self.CancelButton = c
self.ResumeLayout(False)
class UIPanel(FlowLayoutPanel):
def __init__(self):
self.controls = []
self.tabIndex = 0
self.AutoSize = True
self.AutoScroll = True
self.FlowDirection = FlowDirection.LeftToRight
self.WrapContents = True
def addLabel(self, name, text, color, breakFlowAfter):
c = Label()
c.Name = name
c.Text = text
c.AutoSize = True
c.Margin = System.Windows.Forms.Padding(3, 5, 3, 0)
self.SetFlowBreak(c, breakFlowAfter)
self.controls.append(c)
return c
def addNumericUpDown(self, name, lowerLimit, upperLimit, increment, \
decimalPlaces, initValue, width, breakFlowAfter, delegate):
c = NumericUpDown()
c.BeginInit()
c.Name = name
c.TabIndex = self.tabIndex; self.tabIndex += 1
if (delegate != None):
c.ValueChanged += delegate
c.Minimum = lowerLimit
c.Maximum = upperLimit
c.Increment = increment
c.DecimalPlaces = decimalPlaces
c.Value = initValue
if (width != None):
c.Width = width
self.SetFlowBreak(c, breakFlowAfter)
self.controls.append(c)
c.EndInit()
return c
def layoutControls(self):
self.SuspendLayout()
self.AutoSize = True
self.AutoSizeMode = AutoSizeMode.GrowAndShrink
for c in self.controls:
self.Controls.Add(c)
self.ResumeLayout(False)
class TestUI():
def __init__(self):
self.count = 10.0
self.form = UIForm("WinForm Example")
self.form.panel.addLabel("", "move up past 10 to break:", None, False)
self.form.panel.addNumericUpDown("", 1, 50, 1, 2, self.count, 80, \
True, self.OnValueChange)
self.form.layoutControls()
def OnValueChange(self, sender, e):
self.count = sender.Value
if self.count > 10:
#this line breaks the code to demonstrate the issue
rs.LayerId(fakelayer)
if( __name__ == "__main__" ):
Main()
Hi @BenFeicht, i mean like this:
def OnValueChange(self, sender, e):
try:
self.count = sender.Value
if self.count > 10:
rs.LayerId(fakelayer)
except Exception as ex:
print "Message: {}".format(ex)
self.form.Close()
The error is in the Rhino command line. You can decide if it will close the form.
_
c.
1 Like
Wow that did it!
I’m still not sure why Winforms is working differently in R6 & 7 but this way of reading errors works for me.
Thanks!