Grasshopper

algorithmic modeling for Rhino

Dear All,

Can someone explain how recursion takes place in Python within grasshopper. I mean when you use a GH timer recursively apply a python script.

When the timer re-runs, do the variables automatically get saved to the memory? And does that apply to more complicated data like "Lists" "Arrays"...etc?

Thanks,

Omar Helmy

PS. Attached is an example by Marios Tsiliakos for counter done by Python

Views: 1203

Attachments:

Replies to This Discussion

Hi Omar

this is very simple in its concept. There are mainly these two rules:

  1. The interpreter scope is kept for the duration of the script, until you press "Test" again. This way variables "stick" between two runs.
  2. The Grasshopper geometry in rhinoscriptsyntax scope is flushed at the end of each Grasshopper solution. This way Rhino will not finish system memory when you create large amounts of geometry.

Does it help?

Thanks

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

Hi Giulio,

Thank you very much, but I'm not sure I understand. :(

What do you mean by press "Test"?

And what defines a grasshopper solution, I mean isn't it always one solution until you reset?

regards,

Omar

Hi Giulio,

I thought it might be more simple to show you what I'm trying to do. I'm trying to replicate a Cellular Automata code using Python.

The version I came up with works, or at least this is what I thought in the beginning until I realized that each runs (generation) takes a bit longer than the last one.

After some investigation I realized that at each new generation, it resets everything from the beginning and re-runs the whole number of generations that's why it keeps getting longer and longer to run.

This actually defies the whole logic for CA because the cells don't carry over from one generation to the next...

I've attached the definition. Hope you can take a look at it.

Many thanks in advance

regards,

Omar

Attachments:

Hi Omar

I've written a simplified version of your script to show how you would approach this. Rather than giving you the whole solution, I've just taken care of the iterative part of the process, and you can modify the logic of your script as you wish.

If you look carefully, I am sure that you will figure out what generation == 0 does, and how subsequent iterations are handled.

I hope this helps getting you on the right track. It would be cool if you posted your results here, too, later, if you want.

Thanks, kind regards,

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

Attachments:

Hi Giulio,

Thanks a million :)

It finally works... (Check the attached file) You saved me tons of time. Now I can start doing what I wanted to do, which is to apply more complicated rules to CA beyond the "Game of Life"

Feel free to comment on the code if you see necessary.

Many thanks again, much appreciated.

regards,

Omar

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service