algorithmic modeling for Rhino
Hi, recently I have been trying python in grasshopper.
Does anyone know how to convert this C# script(with Timer) to python script?
I just can not figure out....
would be very appreciate, thanks!
I tried this following script and found it so weird........ get error because the variable haven't been declared.
sometimes it works, sometimes not... I have to open the definition and setup the variable first and delete it..... quite strange.
N = 0 (once it works, I open again and delete it)
print("N = %d" %N)
N = N + 1
N = 0
This is a very nice example! One way to avoid the UnboundNameException if Run is False the first time, would be to check the globals dictionary for the presence of the variable. Something like this (attached).
if reset or 'counter' not in globals():
counter = 0
counter += 1
a = counter
for Robert McNeel & Associates
Thank you Giulio,
Actually it always makes sense to perform this check in cases like that, to make your script "user friendly" and error free.
Thanks for pointing that out.
You can also use the scriptcontext sticky for situations like this. Works quite well. Attached a simple example. Hope that helps..
Edit: Marios beat me by a full minute. Nice one ;)
Nice edit: I think I have been at the same place quite a few times by you. maybe we should keep a score board. :)
Hehe, consider it on :D
Marios and Andres, thanks you so much!!!
Both works great, but it seems that sticky is more flexible to extend.
I did a little practice :) make a ball moving, so exciting haha....
now trying to make it more complicated like Classes.
Any suggestion how to make a better code or cleaner?
The classes chapter on this book is quite useful to understand classes and inheritance. If you can code in an oop way in another language you won't be having any issues. The bouncing ball example is perfect for starting working with classes.
hey guys, recently I wrote a python swarm component using class :)
please have a check here. I upload the example definition file, so please try it and do something more fun!
Can someone please 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?