Hey to all,
I am writing a script using Python in Rhino and I would like to use the MessageBox with two buttons: “YES” and “NO”.
I know how to get this box:
rs.MessageBox(’’‘Orientierung des Rumpfes ok?
x=L / y=B / z=D’’’, 4)
… but how can I use the returns?
I know that “YES” has the value 6 and “NO” has the value 7 … but that’s all I know
My script creates waterlines on a ship hull, and I would like the user to check this generated lines.
If the lines are ok, he (or she) can select the “YES”-button and the script continues with more lines (frames, etc).
If the waterlines aren’t correct, he (or she) can select “NO” … I would like the script to stop at this point, so that the user has the chance to correct the wrong lines; after that, he should type “continue” or something like that and it would be great if the script continues then.
I know, two questions in one post aren’t ideal …
But I hope that someone knows a way to solve one of my problems!
Thanks a lot in advance!
Hey to all,
You can get a response to rs.MessageBox certainly, but you cannot “pause” the script to let the user do some stuff, then continue it. Scripts don’t work like that, they have to run until they finish before any other Rhino command can be run.
You can choose to simply stop the script if you don’t get a yes answer - something like:
response=rs.MessageBox('''Orientierung des Rumpfes ok? x=L / y=B / z=D''', 4) if response != 6: #print some sort of message if you like return
The above assuming that your code is encapsulated inside a function definition, otherwise there is no real way to exit the script.
thanks for your answer!
The response-thing really helped, thanks!
Sry for the stupid question … but I’m completly new to this things … it’s my first bigger script!
Hmm … so you say there isn’t a chance to stop the script if the answer is ‘No’ when the code isn’t encapsulated inside a function definition?
Because writing the whole script into a function would really be too long … it’s about 450 lines long
Just write at the top:
def MyFunctionDefinition(): # indent everything below by one tab (normally 4 spaces) <your entire script here> #at the very end, put the following (no indentation): MyFunctionDefinition()
Of course, replace MyfunctionDefinition with whatever name you wish
no spaces, do not start with a number or special character.
You can write other function definitions as well and call then from the main script.
(Changed category to scripting)