Pause script until Enter key is pressed

Hi,

I would like to pause a script to allow the user to move/resize an object manually with the gumball before continuing.

A behavior similar to many commands where the user has to select multiple objects (eg rs.GetObjects) then “Press Enter when done:” would be ideal.

Can anyone help with this?

Thanks

What kind of script? (e.g. command script, RhinoScript, or Rhino.Python)

sorry for omitting that, Python

Can anyone help with this?

I guess in pseudocode it would look something like:

import rhinoscriptsyntax as rs

Points=[[0,0,0],[30,14,0],[-15,-19,0],[0,0,0]]
curve=rs.AddCurve(Points)
rs.SelectObject(curve)
rs.Command("_Gumball " + "On ")

while #("enter key is not pressed"):
    #allow user to modify curve using gumball
    if #"Enter key is pressed":
        #end while loop

When you see the “Press Enter when done” prompt, this is presented by a GetString function.

import rhinoscriptsyntax as rs

print "Before GetString"
rc = rs.GetString("Press Enter to continue")
if not rc is None:
    print "After GetString"    

Thanks for that Dale. It pauses the script until I press enter however the gumball does not appear until after the script has finished. Is there a way to show the gumball whilst the script is running?

Thanks

You can turn the gumball on like this:

rs.Command("_-Gumball _On", False)

Note, if Rhino is in the middle of prompting for a string, you won’t see the gumball…

So I cannot let the user modify a shape via the gumball whilst a script is running?

I don’t believe so, as scripts are linear. Why do you need to do this?

I am trying to achieve something similar to what @jordy1989 is trying to do here - create a dent in an .stl mesh; almost like placing a rock under a sheet although my “rock” has a specific 3d shape. Fortunately the shape of the dent is roughly the same every time although it may be rotated or scaled as desired. I have found that I can achieve the desired dent by using a rectangular CageEdit to the mesh and displacing the cage a predetermined amount.

What I would like the script to do is insert the shape, allow the user to move, rotate and scale the shape to where they want it (the gumball is perfect for this) then apply the cage edit where the shape is. I have everything scripted except the gumball part. Right now the creation of the shape and the Cage Edit scripts are separate to enable the use of the gumball in between however the user has to reselect everything for the second script to work. It would be much easier if this could all be done through one script - hence the desire to use the gumball whilst a script is running.

Is there a way around this?

Thanks for the help!

There really is no way to start and stop a script, allowing some endless operation in between. You might consider breaking you script into two components: a pre and post script, if you will.

That is what I am doing now…
I had wanted a behavior similar to when rs.GetObjects is called where the script allows the user to select multiple objects and press enter when the selection is complete, only I would like the user to be able to use the gumball instead.

i was messing around with the idea of an eraser tool and was able to (sort of) get the ability… (letting the user do things until they press space/return)… couldn’t figure out a way to get the gumball to show up midscript though.

import rhinoscriptsyntax as rs
 
while True:
    pick= rs.GetObject('erase')
    if not pick:
        break
    rs.DeleteObject(pick)