Python rhinoscriptsyntax wish: GetString() and co. should raise exception


#1

Continuing the discussion from Mistake in Python docs? GetString(strings=…) does not return “”:

Hi Steve,

Wouldn’t it be nice in general if pressing ESC throws an Exception in functions like rs.GetString() rather than return None? Usually if the user presses ESC the program should stop.

If you just didn’t consider this case explicitly in your script it does not react sensibly as it is now: It continues (if this None value does not cause an error later on…) If rs.GetString() threw an exception it would stop and by this react precisely as one should expect.

Plus: As pointed out before, it would be nice to be able to differentiate between ENTER and ESC being pressed.

Kind Regards,
Gero.


(Menno Deij - van Rijswijk) #2

You can differentiate between Enter and Escape if you set GetOption’s AcceptNothing to True. Then, if the user presses Enter, GetResult.Nothing is returned and upon pressing Escape, GetResult.Cancel is returned.

At least, that’s how it works in RhinoCommon…


(Steve Baer) #3

Hi Gero,
GetString will return None in SR8 when the user presses escape. I’m not going to make that function throw an exception for the cancel key since that is a perfectly valid key to hit and is not what I would consider an “exceptional” condition. You could easily wrap the GetString function with your own version that does throw an exception when None is encountered.