In certain situation when we develop our AutoCAD add-ins, using a custom command, instead of AutoCAD built-in command, might be preferred and allow our add-in to have more control to specific drafting procedures/steps.
Using DrawJig class we can quite easily to create our own commands that behave similar to, or the same way as, AutoCAD built-in commands, like Move, Copy, Scale, Stretch...
Here I show some code to create a custom "Scale" command that behaves very similar to AutoCAD built-in "Scale" command: user selects an entity, picks a base point, then moves/drags the mouse cursor until the mouse is clicked or a scale number is entered. During mouse dragging, a ghost image of the selected entity dynamically scales in or out, depending on the distance between the cursor's location and the base point.
Here is the class MyScaleJig:
Here is a command class that uses MyScaleJig to scale selected entity:
The key part of the code lies in the 2 overridden methods Sampler() and WorldDraw() and it is quite simple and straightforward.
I uses a non-database residing, cloned entity for generating ghost image of the entity to be scaled. This way, the real entity to scaled is not changed if user cancels dragging, and only be changed when the dragging is ended with a distance (scale) is picked or entered.
As we can see, the whole purpose to use jig here is to get a scale input from user with very user-friendly visual hint help.
With some easy code modification, we can pass a collection/array of selected entities (ObjectIds, actually), and scale them together.
However, comparing to AutoCAD built-in Scale command, one thing is missing: there is no rubber-band line from the base point to the mouse cursor. That is because I have use JigPromptDistanceOptions to acquire user input as scale. In spite I set its UseBasePoint property to True and set its BasePoint property to a Point3d value, the rubber-band line still does not show. I guess this is by design: rubber-band line only shows with JigPromptPointOptions class.
I do not know how to overcome this problem with Jig class. Maybe I can implement another custom Scale command with TransientGraphics in conjunction with Editor.PointMonitor event handler later.
Update: Thanks to Maxence's comment, it turned out showing the rubber-band line is simple. I added one line code, showing in red. Thank you, Maxence.