I don’t understand your question. You typically use things like GetNumber to get numerical input from the user for 1,2,3. I don’t think I’m adding much to this conversation, could you elaborate a little on what you are trying to do?
I got a command thats almost exactly the same (3x or more).
I dont want to make 3 or more commands for this and want to combine them.
So I want to make an If statement in my command that responds on what I put in rhino after my command like
Milling(slow).
Because I filled in slow the command knows what dpj it should load.
The If statements responds on slow, medium, fast with 3 different dpj’s. The only difference is the name of the dpj file.
What I’m doing now is at my current command use:
Dim gs As New Rhino.Input.Custom.GetString()
gs.SetCommandPrompt("Speed (soft, medium, hard):")
gs.AcceptNothing(False)
gs.[Get]()
If gs.CommandResult() <> Rhino.Commands.Result.Success Then
Return gs.CommandResult()
End If
Dim resultaat = gs.StringResult.Trim
and the button command I’m using is Speed slow Is there a better way to do this?
There are two different ways that I would recommend you could approach this; three different command classes with a common abstract base class or using a GetOption and filtering on the selection.
Approach 1 - Three command classes
You could create a common abstract base class that looks something like
Public MustInherit Class CommonBaseCommand
Inherits Command
Protected Function RunCommonCommand(which as Integer, doc As RhinoDoc, mode As RunMode) As Result
RhinoApp.WriteLine(which.ToString())
Return Result.Success
End Function
End Class
Public Class MyCommand1
Inherits CommonBaseCommand
Public Overrides ReadOnly Property EnglishName() As String
Get
Return "MyCommand1"
End Get
End Property
Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
Return RunCommonCommand( 1, doc, mode )
End Function
End Class
Public Class MyCommand2
Inherits CommonBaseCommand
Public Overrides ReadOnly Property EnglishName() As String
Get
Return "MyCommand2"
End Get
End Property
Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
Return RunCommonCommand( 2, doc, mode )
End Function
End Class
Your concrete command classes call the common base class with a different value for “which”
Approach 2 - Use GetOption
This is similar to your GetString approach, but slightly better in that you don’t have to do things like check for correct spelling and the options automatically get set up to work like other commands in Rhino.
'Inside RunCommand
Dim go As New Rhino.Input.Custom.GetOption()
go.SetCommandPrompt("Speed")
Dim soft_option As Integer = go.AddOption("Soft")
Dim medium_option As Integer = go.AddOption("Medium")
Dim hard_option As Integer = go.AddOption("Hard")
go.SetCommandPromptDefault("Soft")
Dim get_result As GetResult = go.Get()
If (go.CommandResult() <> Result.Success) Then
Return go.CommandResult()
End If
Dim which = 1 '2=med, 3=hard
If (get_result = GetResult.Option) Then
If (go.Option().Index = medium_option) Then
which = 2
ElseIf (go.Option().Index = hard_option) Then
which = 3
End If
End If
'do what is appropriate given the input