Context menu for specific entities

Is it possible to enable the context menu only for specific entities? It would be nice if my custom menus showed up only for the entities I target rather than all of them.

I see that the built-in SU context menus are per entity type, so I want to know if the same thing is possible using the Ruby API.

Never mind, this is so easy to implement. I only have to call context_menu.add_item if certain conditions are met.


Also, a UI::Command that can activate a tool, can also have a validation proc that only allows the command to fire (ie, activate the tool or whatever) when certain conditions are met.

Likewise a Tool itself can have it’s own custom context menu. See: Sketchup::Tool#getMenu()
This latter pattern is more powerful than the “plain Jane” UI::add_context_menu_handler() as a tool’s context menu also can (since v2015) accept flags, x, y, and view parameters.

1 Like