Grasshopper

algorithmic modeling for Rhino

How to catch an event from the state change of a booleanToggle component...

Hello everybody.

I'm trying to write a small VB that would let me catch the state change of boolean toggle components, filtered by their specific nick-name.

The purpose is to have the opportunity to change the value of a transform component from several locations of the Grasshopper canvas : I have a rotate component that let me view my design opened r=pi/2 or closed r = 0.
I have many blocks of components to rule my design, so, from any place I'm working on, I use a pair of : booleanToggle + numSlider to remotely drive the opening state.
Toggles(named "ME") are connected to a cullPattern that allows filtering the associated numSlider(named "VAL") with "ME" = true.
It works this way but I need to toggle "ME" = false before to reach another canvas location and use another pair of "ME" = true + "VAL".

As I use that trick pretty often, it would be great If i could feed a VB with a list of booleans + a list of values, and just capture the booleans state change, whatever they are true or false, I will be able to manage who they are from their nickname ("ME_0",...,"ME_n") and retrieve from ("VAL_0",...,"VAL_n").

I have tried things like a loop whith :

    Dim evH As Grasshopper.Kernel.IGH_Component.ObjectChangedEventHandler
    evH.GetType

: that I am not able to manage, and also :

   // Components(name :: category.subcategory {id}
   // Boolean Toggle                 :: Params.Special {ad483f40-dc72-40dc-844d-c9e462c7d19f}

from the "Command: GrasshopperComponentList", that I can't find a way to access, as I don't have any documentation of Grasshopper's object hierarchy ...

Thanks for your help.

Views: 681

Replies to This Discussion

Hi Stanislas,

I'm not sure I understand exactly why you're trying to remotely respond to boolean toggle changes, but I'll try and talk about the order of events.

Boolean Toggles do not derive from GH_Component, instead they derive from GH_Param(Of GH_Boolean). When they expire they raise an event called IGH_DocumentObject.SolutionExpired. You could technically use this to detect these changes.

Here's the bad news, if the GH_Document that owns the Boolean Toggle handles the event first (and it will), then the solution will be recomputed before you even realize what just happened.

Since you hook into a Toggle using your own mechanism, Grasshopper will not expire your VB script before it starts the solution and you're left in the waiting room.


However, I think I misunderstood what exactly you're trying to accomplish. Could you post a VB script component that shows specifically what you're after?

--
David Rutten
david@mcneel.com
Seattle, WA
Dear David, thank you to be everywhere at the same time...

It is my first attempt into Grasshopper's spacename.
I don't have any VB script to show... I was asking for help in order to produce one!

Your explanation is very clear.

I am currently scripting for my own comfort :
the aim is to use several NumberSliders, clones , from various locations on the Canvas, all of them driving the same Rotate component.

In fact, I was fed up moving around a pink group of components to keep them close to the many places where I was fitting other secondary parameters.
I am not getting used to the remote control panel, so I decided to have my 3 main sliders cloned everywhere I need them, dynamically updating each others values... in my poor logic, a BooleanToggle associated with the sliders at a location, was a way to say "Hey! We, n° n of the clones, currently have the hand on it... you others, sharing the same prefix in your NickName, just gently update your values to mine".

It was a poor idea and If I understood clearly your explanation, the event on the sliders components themselves would produce the same result and wouldn't update their values as desired...

Would you please tell me if exists a document describing Grasshopper's namespace ?

Thanks a lot for Monkey, Grasshopper, everything you give in fact ...
Hi Stanislas,

the only documentation I provide is downloadable via the Grasshopper Help menu (Download SDK Help...). It's just the source code xml comments compiled into a windows help file, and a few loose topics on the side.

It's definitely possible (and not even that difficult) to access other objects in the same document, be they sliders or toggles or text-panels or whatever. The difficult bit is the expiration logic. If you need to make sure that your Script is run again whenever a slider is changed or a boolean is toggled, then it will be very difficult.

I attached a script that tries to locate a Text Panel inside the current document, read it's text, then find a slider with that user text name and output the slider value. Hopefully it shows how to navigate the local document and access other Grasshopper objects.

--
David Rutten
david@mcneel.com
Seattle, WA
Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service