About using addoptionlist in getobject class!


#1

I want to use addoptionlist in getobject class. But It seems useless. see the code below. can you tell me where am I wrong. Thank you in advance!

 Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As Rhino.Commands.RunMode) As Rhino.Commands.Result
            Const geometryFilter As ObjectType = ObjectType.Brep
            Dim rc As Rhino.Commands.Result = Rhino.Commands.Result.Failure
            Dim go As New GetObject()
            Dim opbl As New OptionToggle(False, "否", "是")
            'Dim cutmode1 As New OptionToggle(True, "否", "是")
            'Dim cutmode2 As New OptionToggle(False, "否", "是")
            go.SetCommandPrompt("请选取被当前平面切割的物件(Select  Objects to cut)")
            go.GeometryFilter = geometryFilter
            go.AddOptionToggle("是否保留原物件", opbl)
            Dim listIndex As Integer = 1
            Dim opList As Integer = go.AddOptionList("保留侧(Side to reserve)", New String() {"两侧(Both side)", "Z轴正侧(Z aixs side)", "Z轴负侧(-Z aixs side"}, listIndex)
            'go.AddOptionToggle("保留Z轴正向物件", cutmode1)
            'go.AddOptionToggle("保两侧切割物件", cutmode2)

            go.GroupSelect = True
            go.SubObjectSelect = True
            go.EnableClearObjectsOnEntry(False)
            go.EnableUnselectObjectsOnExit(False)
            go.DeselectAllBeforePostSelect = False
            'Dim gop As New Rhino.Input.Custom.GetOption()
            'gop.AddOptionList("保留侧(Side to reserve)", New String() {"两侧(Both side)", "Z轴正侧(Z aixs side)", "Z轴负侧(-Z aixs side"}, listIndex)

            While True
                Dim res As GetResult = go.GetMultiple(1, 0)

                If res = GetResult.[Option] Then
                    go.EnablePreSelect(False, True)
                    If go.OptionIndex() = opList Then
                        listIndex = go.[Option]().CurrentListOptionIndex
                    End If
                    Continue While
                ElseIf res <> GetResult.[Object] Then
                    Return Result.Cancel
                Else

                End If

                'If go.ObjectsWerePreselected Then
                '    go.EnablePreSelect(False, True)
                '    Continue While
                'End If
                Exit While
            End While
            Dim Mcutterplane As Plane = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.ConstructionPlane
            Dim recutterplane As New Plane(Mcutterplane.Origin, Mcutterplane.YAxis, Mcutterplane.XAxis)
            Dim Mreflist As New List(Of ObjRef)
            MsgBox(listIndex)
            For i As Integer = 0 To go.ObjectCount - 1
                Dim Mobjref As Rhino.DocObjects.ObjRef = go.[Object](i)
                Dim Mobj As Rhino.DocObjects.RhinoObject = Mobjref.[Object]()
                If Mobj Is Nothing Then
                    Return Result.Failure
                End If
                Dim Obrep As Rhino.Geometry.Brep = Mobjref.Brep
                If Obrep Is Nothing Then
                    Continue For
                End If
                If listIndex <> 2 Then
                    Dim renewbreps() As Geometry.Brep = Obrep.Trim(recutterplane, RhinoDoc.ActiveDoc.PageAbsoluteTolerance)
                    '   Dim Osrf As Surface = CType(rhinoObject.Geometry, Surface)
                    For Each nbrep As Geometry.Brep In renewbreps
                        RhinoDoc.ActiveDoc.Objects.AddBrep(nbrep, Mobj.Attributes)
                    Next
                    If Not opbl.CurrentValue And renewbreps.Count > 0 Then
                        Mreflist.Add(Mobjref)
                    End If
                End If
                If listIndex <> 1 Then
                    Dim newbreps() As Geometry.Brep = Obrep.Trim(Mcutterplane, RhinoDoc.ActiveDoc.PageAbsoluteTolerance)
                    '   Dim Osrf As Surface = CType(rhinoObject.Geometry, Surface)
                    For Each nbrep As Geometry.Brep In newbreps
                        RhinoDoc.ActiveDoc.Objects.AddBrep(nbrep, Mobj.Attributes)
                    Next
                    If Not opbl.CurrentValue And newbreps.Count > 0 Then
                        Mreflist.Add(Mobjref)
                    End If
                End If
            Next
            For Each oref As ObjRef In Mreflist
                RhinoDoc.ActiveDoc.Objects.Delete(oref, False)
            Next
            RhinoDoc.ActiveDoc.Views.Redraw()
            rc = Rhino.Commands.Result.Success
            Return rc
        End Function

(Dale Fugier) #2

Have you had a chance to review this sample?

– Dale


#3

Yes,I have saw it many times. but I don’t know where my code has problem. getmultiple can’t use addoptionlist??


(Dale Fugier) #4

This seems to work here - what a I missing?

      Dim go As New Rhino.Input.Custom.GetObject()
      go.SetCommandPrompt("Select objects")

      Dim listValues As String() = New String() {"Item0", "Item1", "Item2", "Item3", "Item4"}
      Dim listIndex As Integer = 3
      Dim opList As Integer = go.AddOptionList("List", listValues, listIndex)

      While (True)
        Dim res As Rhino.Input.GetResult = go.GetMultiple(1, 0)
        If (go.CommandResult() <> Rhino.Commands.Result.Success) Then
          Return go.CommandResult()
        End If

        If (res = Rhino.Input.GetResult.Object) Then
          Rhino.RhinoApp.WriteLine("List = {0}", listValues(listIndex))
        ElseIf (res = Rhino.Input.GetResult.Option) Then
          If go.OptionIndex() = opList Then
            listIndex = go.Option().CurrentListOptionIndex
          End If
          Continue While
        End If

        Exit While
      End While

#5

Yes,you have missed special char. It seems I can’t use special character like “-”, space,"()" and so on in listvalues’ element and go.addoptionlist’s english name param.! very weird. try my code,you will find it.


(Dale Fugier) #6

What you say is true - the strings in your list cannot contain special characters, as many of them have other meaning in the context of parsing the command line.


#7

It’s terrible about the help documentation of rhinocommon SDK. I find it’s too hard to write a rhp or gha for developer.HOpe you can’t give some more detail documentation. See the help about cad.net,They have done a good job. I hope you can make a documentation like that. Thank you!
http://docs.autodesk.com/ACD/2014/ENU/index.html?url=files/GUID-4E1AAFA9-740E-4097-800C-CAED09CDFF12.htm,topicNumber=d30e696461


#8

Hi,

is there a way in updating the lets say second option list based on the first option list. If you want to give the option of a List of Lists, how do you do that?

Any help would be great.

Thanks
Christian