Today I’m giving a simple example of how to use a Jig on multiple entities.
There are 2 kinds of jigs (as far as I know, maybe there are new types in the newer API’s):
The EntityJig only allows us to jig one entity at the time, so the type we need here is the DrawJig.
This example is very simple, and by no means exploits full potential of jigging, but it might be something to get you going.
We create a command called ccnSimpleJig (ccn for Cup of Code .Net). The point of this command is to select some polylines, and then use a Jig on them to achieve a similar affect to te MOVE command.
We start by creating the command:
All goes nicely in a transaction. I’m not using a nice Try Catch Finally pattern, because the point here isthe jig.
Next, we select some entities and filter out the Polylines:
Then we prompt for a base or reference point:
Now that we have all this, we can start the Jig, and don’t forget to commit the transaction.
The Jig itself is a class inheriting from the AutoCAD DrawJig class.
When inheriting the DrawJig, you must override (CTRL+ALT+F10 is your friend) 2 Methods: Sampler and WorldDraw.
Sampler simply tells the Jig to sample the needed data, and check if anything needs a redraw.
In WorldDraw, you can then update the entities so that the changes detected in the Sampler method are shown on the screen.
But, first things first, our SimpleGeometryJig Class. In the constructor of this class, we take in a collection of Polylines and a reference point (wich we specified in the command):
Notice that we also use a global Vector2d. This is for tracking the movements, and makes it easy to update the polylines.
So, now our Sample method. Here we are looking for the current mouse position, and we will remember the difference of the current position with the new position. We are also returning Sampler States matching the outcome of the current Prompt (NoChange, OK, Cancel)
In the WorldDraw function, we can now edit the polylines with the calculated vector and draw these changes to the screen.
Voila, Jig is finished.
This is all the code we need, and we have a simple Jig that can move selected entities around.
For more useful and interesting jigs, you should take a look at Kean's site, filtered on the jig-category