Mistake in Python docs? GetString(strings=...) does not return ""


#1

Hi,

Could you please check the documentation of the rhinoscriptsyntax.GetString method? I think it does return None if you just press Enter, at least if you have the optional strings argument. The docstring says it should return “”.

Thanks, Gero.

P.S. I wonder if this kind of issues might be not worth it starting a new toppic. Is this the right place?


#2

This does appear to behave differently from the vb Rhinoscriptsyntax, which does return an empty string. The Help item was copied over from the vb Help…

In looking into it, the problem does not seem to be with Python rhinoscriptsyntax, but rather the RhinoCommon class that the method GetString calls: Rhino.Input.Custom.GetString(). When Get() is called on this, it returns “Cancel” when either Enter(with no text) or Esc are pressed. Thus, it doesn’t seem to know the difference and returns “None” in both cases. I don’t know how easy this would be to fix… Why do you need it to return an empty string?

–Mitch

And yes, this is the right place, and starting a new topic is a good idea.


#3

Thanks for this clarification, Mitch.

No I don’t care if it’s None or an empty string. Just thought it might be worth while updating the docs.

However it definitely would be nice to be able to differentiate between Esc and Enter being pressed by the user. I’m using this function with the optional “strings” argument to choose between some options of the script and this is the last user interaction before the actual process starts. So this would be the last moment to stop the script. That’s why it would be very nice to be able to recognize if the user pressed Esc.

Kind regards, Gero.


Python rhinoscriptsyntax wish: GetString() and co. should raise exception
(Steve Baer) #4

This will be fixed in SR8 where you will be able to differentiate between cancel and enter buttons being pressed. Cancel will return None while enter will return an empty string.

You can try this out before SR8 is released by getting the script from github at
https://github.com/mcneel/rhinopython/blob/master/scripts/rhinoscript/userinterface.py