Every AutoCAD user is used to the fact that when an entity is selected, AutoCAD highlights the entity. However, the default highlight (dashed line) is not that eye-catching enough to satisfy particular drafting need.
I recently worked on a project to converting a fairly complicated VBA program. At a point during that VBA program progress, the VBA program converts the colors of a SelectionSet of entities into a highlight color (for example, yellow, or red), and converts the colors of all the rest of entities into a contrast color. This makes the selected entities much more visually stand out.
Although this achieves the goal of making some entities more eye-catching, it certainly has its drawbacks: it has to change almost all entities in the drawing database, just for the temporary visual effect. If something goes wrong that causes exception, it may leave the entities/drawing in unwanted state (i.e. in a color it should not be).
With Overrule, which was introduced into .NET API since AutoCAD 2010, customizing how an Entity is highlighted becomes an much easier task. There is even a HighlightOverrule class we can use (see one of my old post here ).
However, the HighlightOverrule isn't good enough to meet my need in the VBA conversion project. Besides highlighting the selected entities user selected, it also wants all entities that are not selected are in a plain/dull color so that the selected entities are visually stand-out, visually emphasized. So, I decided to give it a try of using DrawableOverrule. The code presented here is different from what I actually used in the project because of the specific business requirement, though.
Here is the code for a class called HighlightDrawableOverrule:
The code is fairly simple and straightforward: it draws all entities except for the selected in a background color and all selected entities in a highlighted color.
Here is the example of how the HighlightDrawableOverrule class is used:
This video clip shows the effect of running the "HighlightSel" command.
As you can see, using Overrule to change entity's color for temporary visual effect is definitely better than what one have to do in VBA: the entity's color property is not changed at all, thus the draw database remain unchanged, although AutoCAD presents a different color as you needed.
Notice that Editor.Regen() has to be called when the DrawableOverrule started/stopped and when ObjectId is added into selected entity list. If the drawing database is huge, it may take too much time to Regen().