Grasshopper

algorithmic modeling for Rhino

I am running a loop which iteratively grows some geometry. I would like to be able to watch it as it grows, and if possible, do some screen capture of the viewport. 

I have seen some stuff on here for that before, but nothing has worked for me. 

I am coding in Python. 

The only thing I can think to do (or find the commands for) is this

while blah

.....geometry stuff happens here

.....outputs = whatever # although this doesn't update WHILE the thing is looping, only                                    # after it is done - is there a workaround for that?

""" Attempt to redraw viewport """

.....time.sleep(0.05)
.....Rhino.Display.RhinoView.Redraw(scriptcontext.doc.Views.ActiveView)

What am I missing here?

Thanks

Views: 3071

Replies to This Discussion

Hmm, tricky. I'm not sure you can do this using standard Grasshopper preview. It may work, but it may just as easily not. Grasshopper assumes that there will be no viewport redraws during a solution. It builds display caches when the viewports are redrawn and erases those cashes when a solution starts. If you cause a redraw during a solution, the caches may not be valid for the next redraw.

This certainly is the wrong way around:

.....time.sleep(0.05)
.....Rhino.Display.RhinoView.Redraw(scriptcontext.doc.Views.ActiveView)

I don't think time.sleep is going to help much, pausing the current thread for some time isn't going to accomplish anything. You need to redraw the viewports and then maybe make sure all pending messages get handled. I have no idea how to do that in Python.

If that approach doesn't work, you may have to do the drawing yourself.

--

David Rutten

david@mcneel.com

Thanks.

Generally, would it be possible to do this in another language?

So thats sort of what i had done previously, except that the process is iterative, so it has to do the entire calculation from scratch each time, adding one additional iteration for each "frame" of the capture. 

The only way around this I'm aware of is through HoopSnake, but its so tempermental and clunky

edit: Except perhaps what Giulio has mentioned below...

awesome thanks!

The usual way to approach this is to have a result value stored, and update the "iteration" every time the Grasshopper soltion runs. This is perfectly valid in Grasshopper. A good place to store an intermediate value is the sticky dictionary:

scriptcontext.sticky["yourkey"] = yourdata

Additionally, you can just add a boolean toggle that restarts the "iteration" and brings everything to the original state.

I'm pretty sure that there are other ways, but this is probably the simplest one.

Please let me know if this helps,

Thanks, kind regards,

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Giulio, that sounds like exactly what I am looking for. Is that how, say, components in Kangaroo work?

Where might I find more information on what the sticky dictionary is and how to use it?

How does the sticky dictionary differ from a regular dictionary? Given a 'reset' input as you recommend, how would I reset/clear that dictionary?

I found this, which might useful, also this.

Thanks

Hi Harrison,

Technically sticky is a normal Python dictionary however it is globally accessible within an instance of a Rhino which makes it special. For instance, you can add a value to sticky from one component and call it form a different component.

Here is an example that you can see how Steve is using the sticky for a very similar use: http://wiki.mcneel.com/developer/rhinocommonsamples/drawoverlay

Mostapha

cool - I will check this out. Thank you!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service