Grasshopper

algorithmic modeling for Rhino

Hi, I skimmed through previous discussion and I couldn't find a specific post about this so I am creating a new thread.

I am trying to create a simple python script where I would like to have points moving through space given certain rules.

I am running a "for i in range loop", given the number of step my points have to go through, and I am performing all the operations during each step with enable redraw = false.

At the end of each step I am

- enabling the redraw to show only the new positions plus a trail,

- pausing the loop with a time.sleep(n-seconds)

- disabling the redraw

- running the loop again.

The problem is that sometimes, even if it should show what is happening-pause-run again, the redraw just shuts off and the script run until the last loop and then shows the final results.

The only way I found at the moment to keep him working a bit longer is adding a gc.collect(), but I was wondering if there are other way to clean the rhino cache as well (provided it is that that disable the preview of what is happening), or anyway clear garbage data that is piling at each step.

Just to recap the structure would be:

for a certain number of steps

>>> perform some operations

>>> show the results

>>> pause/clear the garbage

>>> hide the visualisation

Thanks in advance

V.

Views: 1816

Replies to This Discussion

If you're writing this in a GHPython component you really should let Grasshopper handle the rendering and not have to deal with the Rhino document. If you want to animate something, one way of doing it is using a combination of the timer and the Python sticky. See attached definition for a simple example. Hope that helps..

Attachments:

Hi Anders, thanks for your reply.

I was actually trying to do it outside grasshopper, however out of curiosity, could you explain me what the sticky library is for? It would look however that I cannot call it by default on the python console (outside gh).

V.

Ah, in that case you'll probably have more luck over on the Discourse forum. Although I would recommend staying in Grasshopper for anything animated and/or interactive as most of the functionality you'll need is already there.

The sticky is a Python dictionary which "sticks" around for the current Rhino session and can be accessed from both the Rhino EditPythonScript and Grasshopper GHPython editors. It is very useful for storing and manipulating data outside of the scope of the script you are running. Making it possible to animate things and even send data back and forth (although the latter is not recommended as it would be rather un-Grasshoppery).

Best,

Anders

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service