GetString Doesn't Accept Empty Spaces

I’m using Rhinoscript GetString to get a string input from the user through the command line. (Python Code) As soon as the user hits the space bar, for example typing first and last name, the command terminates and I only end up with the first name and not the last. How do I get it to accept strings with spaces in them?


hi Eric,
You need to start typing with ", then spaces will work until another ".


Alternatively you can use a string box or edit box to get a longer string

I had been using a box which worked but there was a number of entries and it was annoying having the box open and close multiple times.

Unfortunately the user would never know to do that.

I guess an ETO form would be another option so you can have all the fields visible at the same time. Or, if it makes sense for your inputs, use an edit box with one line per value and then my_text.split('\n') to separate the text into a list of strings…

Unfortunately using space for enter seems to be hard coded into Rhino - I don’t know any way to disable it.

I haven’t played around with ETO Forms just yet. I have users using both rhino six and rhino five. I believe that function is unique to Rhino six?

I’ll look at the edit box. Thanks.

You could print a message to command line with instructions for user to use quotations for strings with spaces. I know its not ideal, I don’t think there is a way around this without using quotes.

Thanks. I saw some other suggestions when searching regarding list boxes. I may try one of those.

Ahh yes a PropertyListBox sounds like it may be ideal for you

I’m updating document user text in Rhino five which is not easily accessible to the user. There are about 10 items to update this is why I don’t want to do them one at a time if I don’t have to. Looks like the property list box
function will do it but I have to try it out.

Hi @eric.bunn,

You can get a string with spaces using Python using GetString.GetLiteralString.

mport Rhino

def test_get_literal_string(prompt):
    gs = Rhino.Input.Custom.GetString()
    result = gs.GetLiteralString()
    if (result == Rhino.Input.GetResult.String):
        return gs.StringResult().Trim()
    return None

str = test_get_literal_string("Layer name")
if str:
    print str

– Dale



Just some feedback to all that helped with this thank you. I settled on using the property listbox and it worked perfectly. Showed my keys in the left column and values in the right Allowing the operator to change values at will. I’ll post the code tomorrow.

This is the code for Rhino6. For some reason in Rhino5 I had to change the line: if rc == None: to `if rc==’ ’ (empty string): Not sure why but it works in both Rhino5 and 6 for changing Key Values for Document User Text in a Title Block.

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

def main():
    #Get All Keys up to 20
    while i <=20:
        rc = sc.doc.Strings.GetKey(i)
        if rc == None:
            break#Get out early if None
            i +=1

    #Get Values and load into keysAll
    keysAll =[]
    for i in Keys:
        docTxt = rs.GetDocumentUserText(i)

    #Display Property List Box
    results=rs.PropertyListBox(items,i_values,"Please adjust values and press Enter")
    #Reload New Values
    num = 0
    for i in Keys:
        num += 1
#Run the main function
if __name__ == '__main__':
1 Like

This worked great. Thanks

GetLiteralString was working for me until I created a toolbar button with the following code in it (used to call the python script) If I manually run the macro from the python editor it works, if I run it with the button it doesn’t work? As soon as I hit the spacebar the code finishes without allowing another character to be typed.

This is the code in the button:

! _-RunPythonScript (

import os
import rhinoscriptsyntax as rs

#Example Code to construct directory path
user = os.environ[“USERPROFILE”];print(user)
subDir = “\FPE Rhino Tools\Title Blocks\”
fpeDir = user + subDir + “Update Doc User Text Import”
print("!-RunPythonScript " + chr(34) + fpeDir + chr(34))

rs.Command("!-RunPythonScript " + chr(34) + fpeDir + chr(34))


This is the function in the python macro:

#Get string including spaces
def get_literal_string(prompt):
gs = Rhino.Input.Custom.GetString()
result = gs.GetLiteralString()
if (result == Rhino.Input.GetResult.String):
return gs.StringResult().Trim()
return None

Thanks for the help.

Follow up to last. The code works in Rhino 6 but not Rhino 5 when called using RunPythonScript.