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?
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.
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.
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.
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():
i=0
rc=""
Keys=[]
#Get All Keys up to 20
while i <=20:
rc = sc.doc.Strings.GetKey(i)
if rc == None:
break#Get out early if None
else:
Keys.append(rc)
i +=1
#Get Values and load into keysAll
keysAll =[]
for i in Keys:
docTxt = rs.GetDocumentUserText(i)
keysAll.append(docTxt)
#Display Property List Box
items=Keys
i_values=keysAll
results=rs.PropertyListBox(items,i_values,"Please adjust values and press Enter")
#Reload New Values
num = 0
for i in Keys:
sc.doc.Strings.SetString(i,results[num])
num += 1
#Run the main function
if __name__ == '__main__':
main()
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 Block.py”
print("!-RunPythonScript " + chr(34) + fpeDir + chr(34))