Grasshopper

algorithmic modeling for Rhino

Probably one for David, but, is it possible to change the component icon based on the user selecting a user defined menu item in grasshopper? I.e. Im overriding the Menu_AppendItem event.

 

As the icon property is read only, I do not see how it is possible to dynamically change the icon based on the user selection.

 

cheers

 

Views: 1237

Replies to This Discussion

Hi Steve,

it's possible but not by assigning a new bitmap to the Icon property. Icon is indeed readonly which means you have to put your logic into the Icon property. It should return a different icon based on the state of your component. That however is the obvious part. The problem is that the Icon property is accessed once and the result is post-processed and cached.

There's two ways of doing it:

  1. Change your Icon property to return different bitmaps depending on the value of of variables somewhere. Then call base.DestroyIconCache and cause a redraw of the canvas (if you're also expiring the solution then the canvas will redraw automatically). This is the best way as it allows GH to cache the icon once for all components that need it.
  2. Call the SetIconOverride() method on your component. This is easy and can be done remotely as SetIconOverride() is a public method. However this approach means that each component with an icon override maintains a pointer to that image. If you get this image from the resources each time you may end up having the same icon image in memory loads of times. However if you have a central place where you keep instances of all your icons then there's no memory overhead.

--

David Rutten

david@mcneel.com

Tirol, Austria

Thabk you david, i am alreasy storing a persistent variable for the user defined type of component i.e standard or advanced so i think the first approach should work for me

As ever, thanks for your prompt and detailed response, cheers

Works perfectly, cheers

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service