[FR] Allow plugin developers to override delete key in their custom tools


Currently pressing delete deletes the selected entities. In most cases this is of course the intended behavior but when creating custom ruby tools this may not always be the case. For instance delete is used in my townhouse system plugin to delete nodes defining the building position.

For now a workaround is to simply empty the selection while your tool is activated but I think it should be possible to have something selected, e.g. component being edited by a plugin, while deleting an “abstract” object used in the custom tool, such as handle of some sort.

Maybe the tool interface could use an “expectBubblingDelete” method that returns a boolean similar to the expectsStartupModelNotifications method of the AppObserver class to allow plugin developers to control this behavior.


Surely getting the selection is important for many tools, but then IF your code needs to ‘disabled’ the delete key’s functionality, then you need to clear the selection - then there’s nothing to be deleted…

Why make it more complex than it needs to be ?


I’m not making it complex. The API is making it complex.

A tool can listen to the delete button and use it to delete an object that doesn’t exist as an entity, e.g. a handle drawn by the tool. I don’t see any reason why users shouldn’t be able to press delete to delete such a handle while simultaneously having geometry selected, e.g. a group or component that the same handle is used to control somehow.


eneroth3: my question of not on topic (delete) but you mention “nodes” and “handles”. How do you simulate these with the methods available in the “tool” class? Can you point to any extensions to illustrate?


By storing their positions/directions as Point3d and Vector3d objects in memory and show them using the View#draw methods.

My townhouse system does this as well as many other plugins: http://extensions.sketchup.com/en/content/eneroth-townhouse-system-beta.


I don’t know the details of your tool, but it sounds like you can enter your tool when Sketchup’s select tool has something selected. A plugin that is not a Tool object could do that and that plugin could obtain the selected data from the select object and not have to provide its own code to select entities. If the plugin is not a Tool object, then any key presses would be ignored until the plugin code completes. If there is a risk of delete key depression deleting something, then after the plugin obtains the details of the object selected, it could:


You say you are using the View#draw method, which only works when called from a Tool object’s draw method. It sounds like your plugin is a Tool object. I’m trying to understand how the delete key could erase an entity without it being under the developer’s control.


I see the View#draw methods for drawing lines, but I was told that polygonal fill color was not supported. Yet I see from your video that have “nodes” depicted as small cubes and cylinders with different fill colors(?)


I’m using View#draw with GL_QUADS as the first argument to draw the filled quads. GL_POLYGON also exists for making other polygons.


But I don’t see how you specify the fill color. I’m looking at the API documentation for View#draw.


It’s simply view.drawing_color, The edges are drawn separately.