algorithmic modeling for Rhino
Hey,
Lets say I have function ("growfunction") in my python script that extends a polyline by one segment for each execution, how do I make it so that I can see the polyline "grow" with each loop in my viewport? I've tried using time.sleep() hoping that I could sneak in an "a=polyline", but nothing shows up in the viewport until the end. How can I see the geometry generated in the python script as it executes in a loop?
import time
For i in range(10):
growfunction(polyline)
a=polyline
time.sleep(.1) 'I want to see the growth of the polyline during this pause'
Thanks
Tags:
Hi Lawrence,
the Rhino viewports update when the solution is finished, so putting delays inside the solution will only slow things down and not cause an update. There are three things you can do I think:
(3) requires the least amount of code, I'd go for (2) but I'm not sure how to even begin doing that in Python.
Here's #2 implemented in C#.
Attached an example of a "randomwalker" I once wrote. It demonstrates how one might approach this using a Python class, the GHPython sticky and a Grasshopper timer.
Thanks for letting me see your script. I understand how your walk function works, but I am not understanding how st['walker'] works. What exactly does sticky do? And what how does the timer affect the loop? Is your script assuming that each iteration takes exactly 1 ms, so your walker is updated right at the end of each iteration?
Essentially I tried this:
from scriptcontext import sticky as st
st[pline]=mypolyline
if toggle:
for i in range(100):
growfunction(st[pline])
a=st[pline]
As I am typing this, I am thinking a few things: does timer run the script over and over? And would that mean that my loop should not occur inside "if toggle:..."? I've noticed that python remembers data from execution to execution, am I supposed to leverage that in this case? Because I am starting new each time by doing "st['pline']=mypolyline".
The "pulse" of a timer resets the script at a given interval, which makes it necessary to store the previous results (variables, lists, etc.) somewhere that doesn't reset. In fact, this script only remembers the data stored in the sticky variable. Sticky variables are persistent, meaning that they don't reset each time the rest of the script does.
Thanks.
Is sticky variable the only way to keep data between each execution? Is sticky variable a grasshopper thing or a python thing?
There are other ways (well at least one), its is Rhino Python thing. See this thread for a good overview and some examples. Thanks for jumping in Marc, been a bit busy lately..
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