Various Addin/API wizards, coders, widgets and examples are provided to help program AutoCAD .NET addins.

05/22/2012

AutoCAD .NET: EntityJig – Dynamic Copy and Jig

AutoCAD .NET API provides two concrete Jig classes for us to jig different entities in different circumstances, EntityJig and DrawJig. EntityJig is to jig a specific entity as its name indicates and the DrawJig is to jig anything that has graphics to draw, which can be a single entity, a group of entities, or something that is not available natively in AutoCAD.

We have demonstrated jigging various AutoCAD entities such as Line, Circle, and Block in many early posts. In this article, let us see how to use jig to copy an entity of any type. Here is the core code of dynamic copy jig along with a test command:

Here is what the the sceen looks like when a solid cylinder is being copied to a new place by the dynamic copy jig:NOTE: The isometric view is in a UCS instead of WCS, indicating our move Jigger honors UCS perfectly.

A few highlights about the code may be helpful:

• No entity type is needed for our Copy Jig since it works for any type of AutoCAD Entity.• A base point needs to be picked to determine where to jig the Entity from. • The Sampler() override is to acquire input for the new location of the base point.• Some UserInputControls flags are used here, GovernedByUCSDetect and Accept3dCoordinates to collect a point from UCS but intepreted in WCS.• If the input is the same as the stored variable, we’d better return SamplerStatus.NoChange to avoid unnecessary flashing; if not, return SamplerStatus.OK.• Please do not forget to handle the cancel/escape circumstance as demonstrated. • The Update() override is to update new location of the Entity through the TransformBy() call on a Vector calculated from the previous base point and the new input location since not every Entity type has an Location or BasePoint property.• The old base point needs to be replaced with the new location just collected so that the next movement can still behave well in every Update() call.• The Editor.Draw() is the power to fire the jig. • The while loop needs to think about the PromptStatus.Keyword case of the PromptResult after each Jig Drag.• Keyword handling code can be added when needed, as commented about.• Only after the jig succeeds should the entity be copied to the new location.