Hi all, I wonder if anyone know how to do Hi-Res capture of the GH canvas via commands in VB.net component. Or if it is possible.
I wanted to make a snapshot for the sliders configuration. Or is there another way to record the sliders info (controlled via VB), similar to the function in the : Solution -> Save State.
Cheers
Victor
David Rutten
Hi Victor,
you can render the current Canvas to a bitmap, if that's not big enough, you can also access the Hi-Res export. It's not very easy, but something along the following should do.
To export the current canvas as a bitmap, you'll need to write something like:
Dim canvas As Grasshopper.GUI.Canvas.GH_Canvas = GH_InstanceServer.ActiveCanvas
If (canvas Is Nothing) Then Return
Dim bitmap As New Bitmap(canvas.ClientSize.Width, _
canvas.ClientSize.Height, _
Imaging.PixelFormat.Format24bppRgb)
canvas.DrawToBitmap(bitmap, canvas.ClientRectangle)
bitmap.Save("C:\GrasshopperCanvasScreenshot.png")
bitmap.Dispose()
However, it sounds like you want to save information, not images. You won't be able to automate the Save State logic because you can't get around the state properties window (well, you can if you're willing to write xml directly)
A simpler mechanism would simply be to find all sliders in the document and store their current value in your own data structure. Be it in memory, or in a file on the disk, or in a database somewhere:
Dim sliderDataBase As New SortedList(Of Guid, Decimal)
For Each docObject As IGH_DocumentObject In owner.OnPingDocument().Objects
Dim slider As Special.GH_NumberSlider = TryCast(docObject, Special.GH_NumberSlider)
If (slider IsNot Nothing) Then
sliderDataBase.Add(slider.InstanceGuid, slider.Slider.Value)
End If
Next
'At this point you can write the sliderDataBase to file, or whatever.
You can re-instate a slider record by using the Find() method on GH_Document to find the object with a certain Guid, then TryCast that object to a GH_NumberSlider and set the Value.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Aug 1, 2011