How to obtain the all views information

Hi every one, for some reasons, I hope the top and perspective view could
rotate 180 degree by y-axis, and give the nameview-top1, perspective1.

and the following code can finish this work.

  Dim num As Integer
        num = RhinoDoc.ActiveDoc.Views.Count
        Dim vp11(num - 1) As Rhino.Display.RhinoView
        For i = 0 To num - 1
            vp11(i) = RhinoDoc.ActiveDoc.Views.ElementAt(i)
            If vp11(i).ActiveViewport.Name = "Perspective" Then
                vp3 = vp11(i)
                vp3.ActiveViewport.Rotate(PI, VECC, pt0)
            End If
            If vp11(i).ActiveViewport.Name = "Top" Then
                vp2 = vp11(i)
                vp2.ActiveViewport.Rotate(PI, VECC, pt0)
            End If
        RhinoDoc.ActiveDoc.NamedViews.Add("Perspective1", vp3.ActiveViewport.Id)
        RhinoDoc.ActiveDoc.NamedViews.Add("Top1", vp2.ActiveViewport.Id)

But the active view maybe exist two perspectives and the top is disappear in some situations, and I must to find top view information from the viewtable list (see the following figure) , could anyone tell me how to write the program to obtain the all
views information(not only limit the active document)

Hi @jerry1,

It is probably best to not look for view orientations based on the name, which is localized, can be changed by the user, and may not accurately describe the view’s orientation.

Consider the following utility functions:

Protected Function IsRhinoViewPerspective(ByVal view As RhinoView) As Boolean
  Dim rc As Boolean = False
  If view IsNot Nothing AndAlso view.ActiveViewport.IsPerspectiveProjection Then
    rc = True
  End If
  Return rc
End Function


Protected Function IsRhinoViewTop(ByVal view As RhinoView) As Boolean
  Dim rc As Boolean = False
  If view IsNot Nothing AndAlso view.ActiveViewport.IsParallelProjection Then
    Dim top_dir As New Vector3d(0.0, 0.0, -1.0)
    Dim cam_dir As Vector3d = view.ActiveViewport.CameraDirection
    If top_dir.IsParallelTo(cam_dir) Then
      rc = True
    End If
  End If
  Return rc
End Function

You can use these from a simple Rhino plug-in command:

Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result

  Dim perspective_counter As Integer = 1
  Dim top_counter As Integer = 1

  Dim pi As Double = Math.PI
  Dim axis As Vector3d = Vector3d.YAxis
  Dim origin As Point3d = Point3d.Origin

  Dim standard_views As RhinoView() = doc.Views.GetStandardRhinoViews()
  For Each view In standard_views
    Dim name As String = Nothing

    If IsRhinoViewPerspective(view) Then
      name = view.ActiveViewport.Name & perspective_counter.ToString()
      perspective_counter += 1

    ElseIf IsRhinoViewTop(view) Then
      name = view.ActiveViewport.Name & top_counter.ToString()
      top_counter += 1
    End If

    If Not String.IsNullOrEmpty(name) Then
      view.ActiveViewport.Rotate(pi, axis, origin)
      doc.NamedViews.Add(name, view.ActiveViewportID)
    End If



  Return Result.Success

End Function

Does this help?

– Dale