algorithmic modeling for Rhino
Hey,
I'm trying to make educational material with grasshopper and karamba.
My goal is to apply a changing force on a building and record how the response changes. If i'll use slider for it the result is not very professional since i have to slide trough the values manual. I was thinking of using a simple python loop to go though values I wrote the following code:
import time
def main():
x = int(0)
while x < 201:
x += 1
time.sleep(0.1)
return x
main()
But it seems not to do anything. Any ideas?
Tags:
Hi Matti,
try to assign the result of the function to the output variable, like so:
import time
def main():
x = int(0)
while x < 201:
x += 1
time.sleep(0.1)
return x
x = main()
I hope this helps,
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
Thanks for the answer Giulio,
I just noticed that there is a flaw in my thinking.
It seems the python script cannot return values while it running, meaning that with that script it returns value 1 which is the the value of x before first return.
So I cannot run an "animation" with python script because it does not give values out while it running, am i correct?
Ok I used hoopsnake to do the animation and it seems to work well, but i'm still interested of the limitations of scripting so if i can get an answer to my previous question i would be grateful.
Hi again Matti,
What you are saying is possible but a little more involved because we are already in a loop, which is defined in Grasshopper, and we are running along a directed graph. There's a difference between running a loop in the script, and running one in the external Grasshopper definition. Both are possible.
For the external ones, a way is to save a value and use in the later solution (Grasshopper definition solution). In Python this usually looks like using the sticky dictionary or a retained variable. See some examples here and here. I'm also attaching two components, one showing again the method of the variable, and one that listens to the end of the solution and then schedules a new one...
I hope this helps,
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
The sticky example also with a small example
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by