Grasshopper

algorithmic modeling for Rhino

In one of the recent releases of Grasshopper, the Export Quick Image interface was included with Grasshopper (which is pretty sweet).  My question: is there a method which I can use to return a bitmap of the Rhino Viewport (like in the Toggle Viewport Frame button)? 

Views: 1871

Reply to This

Replies to This Discussion

Rhino.Display.RhinoView.CaptureToBitmap(New Size(width, height))

Or use the ViewCaptureToClipboard command...

--

David Rutten

david@mcneel.com

Tirol, Austria

Thanks for the quick reply.  However, when I type in Rhino.Display.RhinoView... I don't see the CaptureToBitmap method.  Is this public?

It is public, but you need to call it on an instance of the RhinoView class. Not the on the class itself. I.e. in the Quick Export window, I use the following code:

Private Sub UpdateViewportImage()
  Dim vp As Rhino.Display.RhinoView = Nothing
  If (Not String.IsNullOrEmpty(ViewportName)) Then
    For Each view As Rhino.Display.RhinoView In Rhino.RhinoDoc.ActiveDoc.Views
      If (view.MainViewport.Name.Equals(ViewportName, StringComparison.OrdinalIgnoreCase)) Then
        vp = view
        Exit For
      End If
    Next
  End If
  If (vp Is Nothing) Then
    vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView
  End If

Dim pts As PointF() = ViewportFramePoints
Dim width As Int32 = Convert.ToInt32(GH_GraphicsUtil.Distance(pts(0), pts(1)))
Dim height As Int32 = Convert.ToInt32(GH_GraphicsUtil.Distance(pts(0), pts(3)))
width = Math.Max(10, width)
height = Math.Max(10, height)

Dim capture As Bitmap = vp.CaptureToBitmap(New Size(width, height))
If (capture IsNot Nothing) Then
  If (ViewportImage IsNot Nothing) Then
    ViewportImage.Dispose()
    ViewportImage = Nothing
  End If
  ViewportImage = capture
  ImagePanel.Invalidate()
End If
End Sub

--

David Rutten

david@mcneel.com

Tirol, Austria

Cool.  Works like a charm.  Thanks so much for the help.

Great I mark it.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2019   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service