Grasshopper

algorithmic modeling for Rhino

Would it be possible to set the interval of the GH timer dynamically? Like if I wanted the timer to fire every 100 ms for 5 seconds and then every 500 ms for the next 5 seconds?

It would be great to be able to input a pattern of delays until the timer fires again.

Could you script this using the ScheduleSolution Method with a delay parameter that changes? I'm trying to create a loop that would count from some user-defined variable to another user-defined variable with variable delays between each iteration - Essentially a counter with variable step durations.

Any pointers would be greatly appreciated.

Thanks,

-Brian

Views: 4129

Replies to This Discussion

Private Sub RunScript(ByVal run As Boolean, ByRef A As Object)
If run = True Then
If counter <= 49 Then
A = counter
Else If counter > 49 And counter <= 100 And counter Mod 5 = 0 Then
A = counter
Else
A = 0
End If
counter = counter + 1
Else
counter = 0
End If

End Sub

'<Custom additional code>
Dim counter As Integer = 0

Why not to make it like this ? With some more inputs you'll have pretty good control over time... (remember to add timer)

Hey Mateusz, thanks for the reply. Unfortunately I am looking for something a little different - I'd like to be able to control the duration of each "count" by implementing a delay (which will change over time) between each count. Otherwise this script would essentially be the same as the Firefly counter.

Actually looking at your code again, is "counter Mod 5 = 0" referring to a variable modulus? I guess that could sort of be used to create variable delays (when the modulus = 5, the timer will only fire every 5 intervals (which would be constant in this case e.g. 100 ms or something).

I'll think more on it... Davids words seem encouraging though, so I think I'm going to start off on that route.

Hi Brian,

1) No

2) Yes

ScheduleSolution is in fact how the timer works, I felt it prudent to put all the bookkeeping logic in the GH_Document class rather than the GH_Timer object, as it would then be accessible to all.

There's two steps to using ScheduleSolution in order to create a recurring event:

  1. During SolveInstance (or RunScript if you're doing this in a VB/C# script component) you should call ScheduleSolution with whatever delay you want.
  2. In order to ensure that SolveInstance (or RunScript) is called again the next time a solution runs, you must register a callback delegate of the type GH_ScheduleDelegate. This delegate will be invoked just before the next solution kicks off. Inside this delegate you must expire any and all objects that ought to be resolved.

Is that enough to get you started?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Yes, that's great. I'm going to take a stab at it tonight. 

Thanks David

-Brian

I'm curious to know how Davids approach would look like. With my humble knowledge of the GH-object model I would try something like this:

Connect a timer based on the quickest delay of 20 ms with a custom C# component. Also I would feed the component with a list of delays requested. Inside the C# component I would add up 20 as long as the first value out of my list isn't reached, otherwise I would shift the list by one and set the counter variable to 0 starting over and over until the delays are exhausted..

A first test showed that this approach is not very precise due to the simple reason that solving the instance also takes XX ms. Probably working with a date-object inside the C# component to measure a period of time would produce better results. 

Attachments:

Hi Brian

I've looked at this after your private message. A possible way to approach this is attached.
I've chosen to modify the 'trampoline' script so you can see the complete code. Keep in mind that the canvas redrawing and the Rhino viewport redrawing take some time as well (on my system 6 ms for the empty Gh canvas and 28 ms for the empty Rhino viewport). No timer can avoid that, to my knowledge. The trampoline computes timing after the solution is complete. This means that one cycle is: solution completed + drawn + user specified interval.

Hope that this helps to get started,

- Giulio
________________
giulio@mcneel.com

Attachments:

Hey Giulio,

Thanks for that. David helped me out with this too, so now I have some really great references for timer-related scripting (thanks to you both).

Is there a way to get the script to return the interval of time it takes to complete events like rhino viewport redrawing and GH canvas redrawing? If so it would be cool to have the script perform one test count to calculate these durations, and then subtract the result from each delay pattern in order to compensate for the GH/rhino redrawing. This wouldn't be perfect, but I think it would be pretty close.

Also where are you getting your redraw times from? I'm not sure how to monitor them (the profiler doesn't do this, does it?). I'd like to see how my computer performs as well.

-thanks,

Brian

> where are you getting your redraw times from?

Hi Brian,

I quickly wrote a script for that, with no pretensions to high precision.

For example, for the Rhino redraw time, I wrote a loop that draws the screen 100 times, and saw how long that took. The basic method is doc.Views.Redraw();

For Grasshopper there is an item in the menu.

I hope that helps,

- Giulio
________________
giulio@mcneel.com

I see. So you could take that quick component and view it's performance with the system profiler. Is there a way to have that simple script output how many milliseconds it took to complete some number of redraws?

Also Is there a scripted method for getting the GH redraw time?

Thanks Giulio,
Brian

"Also Is there a scripted method for getting the GH redraw time?"


No. You can just call Redraw() on the active canvas X times and measure how long it takes. Don't call Invalidate(), because then the redraws will be delayed until the processor falls silent on the Rhino UI thread.


--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hello Giulio and all.

I have tried to use this definition to do an animation where a curve is revealing my path made from my GPS data taken with my phone. I converted the time values in delays that I would like to set as step values in this component. However, as the values are low it stops after 6 steps and I dont understand why. Also not sure about the best way to record it. Do you have ideas ? 

Thank you 

Yannis

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