Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:activeviewport [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Determine Active Viewport =====
 +
 +===== C# =====
 +<code c#>
 +public static Rhino.Commands.Result ActiveViewport(Rhino.RhinoDoc doc)
 +{
 +  Rhino.Display.RhinoView view = doc.Views.ActiveView;​
 +  if (view == null)
 +    return Rhino.Commands.Result.Failure;​
 +
 +  Rhino.Display.RhinoPageView pageview = view as Rhino.Display.RhinoPageView;​
 +  if (pageview != null)
 +  {
 +    string layout_name = pageview.PageName;​
 +    if (pageview.PageIsActive)
 +    {
 +      Rhino.RhinoApp.WriteLine("​The layout {0} is active",​ layout_name);​
 +    }
 +    else
 +    {
 +      string detail_name = pageview.ActiveViewport.Name;​
 +      Rhino.RhinoApp.WriteLine("​The detail {0} on layout {1} is active",​ detail_name,​ layout_name);​
 +    }
 +  }
 +  else
 +  {
 +    string viewport_name = view.MainViewport.Name;​
 +    Rhino.RhinoApp.WriteLine("​The viewport {0} is active",​ viewport_name);​
 +  }
 +  return Rhino.Commands.Result.Success;​
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Shared Function ActiveViewport(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result
 +  Dim view As Rhino.Display.RhinoView = doc.Views.ActiveView
 +  If view Is Nothing Then
 +    Return Rhino.Commands.Result.Failure
 +  End If
 +
 +  Dim pageview As Rhino.Display.RhinoPageView = TryCast(view,​ Rhino.Display.RhinoPageView)
 +  If pageview IsNot Nothing Then
 +    Dim layout_name As String = pageview.PageName
 +    If pageview.PageIsActive Then
 +      Rhino.RhinoApp.WriteLine("​The layout {0} is active",​ layout_name)
 +    Else
 +      Dim detail_name As String = pageview.ActiveViewport.Name
 +      Rhino.RhinoApp.WriteLine("​The detail {0} on layout {1} is active",​ detail_name,​ layout_name)
 +    End If
 +  Else
 +    Dim viewport_name As String = view.MainViewport.Name
 +    Rhino.RhinoApp.WriteLine("​The viewport {0} is active",​ viewport_name)
 +  End If
 +  Return Rhino.Commands.Result.Success
 +End Function
 +</​code>​
 +===== Python =====
 +<code python>
 +import Rhino
 +import scriptcontext
 +
 +def ActiveViewport():​
 +    view = scriptcontext.doc.Views.ActiveView
 +    if view is None: return
 +    if isinstance(view,​ Rhino.Display.RhinoPageView):​
 +        if view.PageIsActive:​
 +            print "The layout",​ view.PageName,​ "is active"​
 +        else:
 +            detail_name = view.ActiveViewport.Name
 +            print "The detail",​ detail_name,​ "on layout",​ view.PageName,​ "is active"​
 +    else:
 +        print "The viewport",​ view.MainViewport.Name,​ "is active"​
 +
 +
 +if __name__ == "​__main__":​
 +    ActiveViewport()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/activeviewport.txt ยท Last modified: 2015/09/14 (external edit)