Grasshopper

algorithmic modeling for Rhino

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

Views: 617

Replies to This Discussion

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

Hi David, Tks a lot for the reply. 

 

The first method I could not make it work, it keep returning "A generic error occurred in GDI+"

 

The second method I have some good result, I found that under the docObject As IGH_DocumentObject , I can have:

docObject.Description()

docObject.Name()

docObject.Nickname()

which are all very interesting, And I could potentially save other types of input too.

In slider As Special.GH_NumberSlider

Slider.SaveState() gives me the XML doc, which is cool.

 

A few more question:

I realize that it would be quicker if I initialize a Save As Copy (Save as backup), and how would I do this in VB? (sorry, I tried a while, and still couldn't find the method)

I dont understand why would you use SortedList instead of List, to preserve the Guid?

 

I seem to be adding workload to you every time I ask a question. It seem to me that the only rationale is to spark a question that potentially expand the knowledge base in this forum from your answers.

If you want to trigger a Save As Backup, you'll have to mimic the code inside the menu item, as the menu is only accessible from within the Grasshopper assembly. This actually makes it impossible for people other than me to interact with the menu through code, and I'm not yet decided on whether that's a bad thing or not.

 

All file operations (Open, Save, SaveAs, Copy, Paste and so on) are however easily accessible via the GH_DocumentIO class.

 

Dim io_util As New GH_DocumentIO(doc)     

io_util.SaveBackup()

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service