Winforms not returning errors in Rhino 6

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:

    # 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.

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()

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
        ctrlList = self.panel.Controls.Find("Cancel", True)
        if (len(ctrlList) != 0):
            c = ctrlList[0]
            self.CancelButton = c
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)
        return c
    def addNumericUpDown(self, name, lowerLimit, upperLimit, increment, \
        decimalPlaces, initValue, width, breakFlowAfter, delegate):
        c = NumericUpDown()
        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)
        return c
    def layoutControls(self):
        self.AutoSize = True
        self.AutoSizeMode = AutoSizeMode.GrowAndShrink
        for c in self.controls:

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)
    def OnValueChange(self, sender, e):
        self.count = sender.Value
        if self.count > 10:
            #this line breaks the code to demonstrate the issue

if( __name__ == "__main__" ):

Hi @BenFeicht, i mean like this:

    def OnValueChange(self, sender, e):
            self.count = sender.Value
            if self.count > 10:
        except Exception as ex:
            print "Message: {}".format(ex)

The error is in the Rhino command line. You can decide if it will close the form.


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.