Grasshopper

algorithmic modeling for Rhino

Hi everyone,

Just making some test with events and handlers, I'm trying to create an event handler that tracks param changes in a component. I've made a very simple implementation, just to clarify the concepts around event handling in Grasshopper. The code works, but I don't know why my handler is activated 3 times in a row every time a param (in my case a single param) is changed. I can fix the problem with number/3 but I want to understand why this is happening. 

Thanks in advance.

Cheers,

Ángel.

Public number As Integer = 0


Protected Overrides Sub RegisterInputParams(pManager As GH_Component.GH_InputParamManager)

pManager.AddNumberParameter("Number A", "A", "First input parameter to test", GH_ParamAccess.item)


End Sub

Protected Overrides Sub RegisterOutputParams(pManager As GH_Component.GH_OutputParamManager)
pManager.AddIntegerParameter("C", "Changes", "Count the number of changes through A event handling", GH_ParamAccess.item)
End Sub

''' The EventHandler.


Private Sub ParamChangeHandler(ByVal sender As Object, ByVal e As GH_SolutionExpiredEventArgs) Handles MyBase.SolutionExpired

number = number + 1

End Sub

Protected Overrides Sub SolveInstance(DA As IGH_DataAccess)

Dim result As Double = Nothing

If (Not DA.GetData(0, result)) Then Return

DA.SetData(0, number)


End Sub

 

Views: 494

Replies to This Discussion

SolutionExpired gets raised all the time, even when the solution is expired while the object is already in an expired state. What things do you actually want to watch?

--

David Rutten

david@mcneel.com

Hi David, thanks for the reply.

I just want to be able to know when a parameter or a component linked to it changes. Dividing by 3 "number" in my code I get what I want: number only increments when a parameter related with my component changes. But its strange that always "number" is 3 times bigger than you could expect.

As you can see in the image every component counts only the events when a parameter or a component linked to this parameter directly or downstream changes (a timer attached to one of that components will work too).

Attaching the compiled *gha file. 

Attachments:

"I just want to be able to know when a parameter or a component linked to it changes."

Expiration doesn't mean anything necessarily changed. What sort of changes are you interested in? Nicknames, Preview, Persistent Data, Flattening/Grafting/Reversing post processes, or anything that affects the output data?

You can watch for the Expired event, but don't collect subsequent events. Then, when the SolutionStart event on GH_Document is raised you increment your counter. 

--

David Rutten

david@mcneel.com

Hi!

I need to know when something (anything but mainly data structure or data) has changed and is related to my component, because a need to send a command to restart a process out of grasshopper that depends on that data.

So, for instance, if my component is receiving 3 strings and at some point that data changes (structurally or "physically")  I have to know it to wipe the old data in my third app and send the new one. 

I know that with my clunky method I'm counting more events than necessary but at least I'm on the safe side, avoiding data collision on the third app. If you have any suggestion to improve the performance and the general behaviour of the event listening system I'll appreciate it. 

Thanks.

Ángel.

Mmmm...taking some data from here, Jon had the same problem that I had. The 3rd party software is different but the concept is the same.

http://www.grasshopper3d.com/forum/topics/grasshopper-calculation

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service