Grasshopper

algorithmic modeling for Rhino

Listening for component deletion/change/nickname change etc.

Hi everyone,

 

I am developing a component for Grasshopper which is referencing various other components within a document. I would like for it to be able to listen to events such as when a referenced component has been deleted or a parameter attribute (such as a nickname) has changed.

 

What would be a good practice to listen for changes in components and/or their parameters, irrespective of solution changes, e.g. when a user deletes a component or changes an attribute? Which event provides an accurate update to these types of changes?

 

Thank you.

 

Yiannis

 

Views: 706

Replies to This Discussion

Hi Yiannis,

 

there are no events like this I'm afraid. The stuff you describe is usually followed by some form of event, but it will take some bookkeeping on your part as well. GH_Document raises events when objects are added or deleted:

 

Public Event ObjectsAdded(ByVal sender As Object, ByVal e As GH_DocObjectEventArgs)

Public Event ObjectsDeleted(ByVal sender As Object, ByVal e As GH_DocObjectEventArgs)

 

And there's also an event when the undo-state is changed. It is however the responsibility of the code changing a nickname to add an undo record for this.

 

Public Event UndoStateChanged(ByVal sender As Object, ByVal e As GH_DocUndoEventArgs)

 

Then there are redraw events on the canvas that you can use to check for things, but obviously this is quite performance critical code so your tests should be snappy.

 

Public Event CanvasPaintBegin(ByVal sender As GH_Canvas)

Public Event CanvasPaintBackground(ByVal sender As GH_Canvas)

 

Finally you can put checking code into the draw call of your own attributes. This is what I do with groups for example. Calculating the outline of a group object can be an expensive operation so I cache the result. I also cache a list of rectangles of all the objects inside a group. Then, just before I draw the group, I run through the objects, get their boundingbox and compare them to my cached list of rectangles. If I detect a difference, I recompute the group outline.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

David,

 

thanks very much for the thorough reply. ObjectsAdded & ObjectsDeleted is the most important for me, to maintain consistency among the references. Of course, there is still the issue of e.g. a parameter being removed from an object, but that, as well as changes in nicknames etc. can indeed be handled during UI updates.

 

Thanks again

Yiannis

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service