Grasshopper

algorithmic modeling for Rhino

Hello,

I'm trying to count up to a certain number and trigger or call methods at different stages of the counting.
I've tried to accomplish that with the Grasshopper timer plugged directly into the pyhton container and a boolean toggle to trigger the following script:


def counter(run):
    if run == True:
        counter =+ 1
    else:
        counter = 0
return counter

It works great, but the problem is that the timer runs the script for each iteration that it counts. I believe this is due to the fact that the Pyhton container refreshes everytime it is passed a new value?
I have like 30 functions that get called for each and every timer iteration every 500ms.
I want the timer to simply keep count, so that I can call the methods that I want at certain intervals:

if counter(run) <= 20:
    "call a method"
elif counter(run) > 20 AND counter(run) <= 40:
    "call the next method"

Is this even possible? Or is there a workaround?
I'm kinda lost here.

Views: 1601

Replies to This Discussion

The VB and C# components have overrides called BeforeRunScript and AfterRunScript which are called only once per solution. The VB and C# components also have an Iteration field which will be zero the first time the script runs per solution.

If python doesn't provide that, you can handle the SolutionStart or SolutionEnd events on GH_Document.

--

David Rutten

david@mcneel.com

Thanks, but how do I access GH_Document? In the python script or elsewhere?

You can access the GH_Document like so:

ghComp = ghenv.Component
ghDoc = ghComp.OnPingDocument()

can you please explain this in more detail ?

@Piac , Hey Giulio ,
is there a way to do this in python (( without GH_document )) ?

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service