Select object or Enter for...option


#1

I’m dipping my toes into RhinoCommon with Vb and there may be a sample already that shows this but I haven’t found it yet… I want to do an optional object pick where the user can select an object or hit Enter to continue without it. EDIT…I thought I had it figured out but it seems to “cancel” if I use Enter or ESC.


#2

Something like this?

Dim SelectedObj As Rhino.DocObjects.ObjRef = Nothing
Dim Res As Rhino.Commands.Result = Rhino.Input.RhinoGet.GetOneObject("Select an object", True, DocObjects.ObjectType.AnyObject, SelectedObj) 
If Res <> Rhino.Commands.Result.Success Then
'No object selected
End If

Selected object is in SelectedObj, If no objects selected it will get in the 'No object selected part :slight_smile:


#3

Okay, but how do you distinguish between not selecting anything and cancelling?


(Dale Fugier) #4

Hi Jim,

Try the following:

Dim go As New Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select object, or <Enter> to continue")
go.AcceptNothing(True)

Dim res As Rhino.Input.GetResult = go.Get()

Select Case (res)
  Case Rhino.Input.GetResult.Object
    Rhino.RhinoApp.WriteLine("Object selected")
  Case Rhino.Input.GetResult.Nothing
    Rhino.RhinoApp.WriteLine("Object selected")
  Case Else
    Return Result.Cancel
End Select

' TODO...

(Steve Baer) #5

The ‘AcceptNothing’ line in Dale’s sample is the key. When this is set to true, then the enter key will give a result of Nothing instead of Cancel.


#6

Cool, thanks!