Site Tools

Obtaining the Resolution of a Viewport

Developer: .NET
Summary: Demonstrates how to get the pixel resolution of a viewport.
NOTICE: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here


I want know how to get the viewport resolution via the SDK. The language is C#.



public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  MRhinoView view = RhUtil.RhinoApp().ActiveView();
  if (null != view)
    string name = view.ActiveViewport().Name();
    int left = 0, right = 0, bottom = 0, top = 0;
    view.ActiveViewport().VP().GetScreenPort( ref left, ref right, ref bottom, ref top);
    int width = right - left;
    int height = bottom - top;
    RhUtil.RhinoApp().Print(string.Format("Name = {0}: Width = {1}, Height = {2}\n", name, width, height));
  return IRhinoCommand.result.cancel;

developer/viewportresolution.txt ยท Last modified: 2020/08/14 (external edit)