Getting text information from "EditBox" / Python for Rhino

Hey,
.
I have a question about a tool in Python for Rhino called “EditBox” …
… it’s possible to let a box pop up which asks the user for text.
I would like the user to type in three values and then use this values …
does anybody know how to do this?
.
For example:
.
TrRa=rs.EditBox(message=(’’‘Kumulatives Volumen zur Bestimmung
der Traegheitsradien angeben:
VOL_kum [m^3]:
Ix [m^5]:
Iy [m^5]:
Iz [m^5]:’’’))
.
The input from the user should look like:
.
1.0773
0.0222
4.3679
4.4578
.
.
Then, I would like to use these four values for different calculations … is it possible to get the single values (like out of a list?)?
.
Many thanks,
Phil

You might want to check out rs.PropertyListBox… If you’re runing on Mac, however, none of the …ListBox methods work (yet). --Mitch

Here is a quick code sample to test. Note that the method outputs the results as strings, so if you need numbers you will need to convert. It also does not limit what you can enter into the boxes, so if you enter things other than numbers, it will error out (hence the try/except clause).

import rhinoscriptsyntax as rs

items=["Item 1","Item 2","Item 3"]
i_values=[1.0,2.0,3.0]
results=rs.PropertyListBox(items,i_values,"Please adjust values and press Enter")
if results:
    try:
        new_values=[float(s) for s in results]
        print new_values
    except:
        print "Conversion of results to numbers failed!

Wow, perfect!
Thanks a lot :smiley:

… and one last question:

I would like to write the results into a Message Box, that appears in Rhino.

Does anybody know, how to get variables/results into a text that is longer than one line?
It should look like:

ix: 12345
iy: 45678
iz: 78910

For showing the results in one line, I could write:
print 'ix: ', ix, 'iy: ', iy, 'iz: ', iz
… I know how to use the triple quotation mark for texts, but not how to get variables into the text … :confused:

Would be great to hear from you! : )

Hmm … try and error helped also :wink:

… did it with the “%f”-function! : )

The python symbol for new line is '\n'. So, if you want multiline text:

mls="'Twas brillig, and the slithy toves\n"
mls+="Did gyre and gimble in the wabe.\n" 
mls+="All mimsy were the borogoves,\n"
mls+="And the mome raths outgrabe."
print mls

–Mitch

Oh, and I don’t know if this was a separate question or not. One of the nice ways to get data inserted into a text string is to use the .format method. Have a look at the Python help for string formatting for more info. In short, it’s a substitution type of arrangement:

a=4
b=7
"{} score and {} years ago...".format(a,b)

>>> 4 score and 7 years ago...

The values in parentheses get substituted into the brackets in order from left to right. There are many options available for formatting various types of data correctly into strings.

HTH, --Mitch