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 a line segment or multiple segments using the same line jig earlier. In this article, let us see how to add the dynamic dimension support for line jigging.
Here is the core code of the DynDimLineJigger along with a test command:
#region Namespaces
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Windows;
using MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using MgdAcDocument = Autodesk.AutoCAD.ApplicationServices.Document;
using AcWindowsNS = Autodesk.AutoCAD.Windows;
#endregion
namespace AcadNetAddinWizard_Namespace
{
public class DynDimLineJigger : EntityJig
{
#region Fields
public int mCurJigFactorIndex = 1; // Jig Factor Index
public Point3d mStartPoint; // Jig Factor #1
public Point3d mEndPoint; // Jig Factor #2
private DynamicDimensionDataCollection dddCollection = new DynamicDimensionDataCollection();
Here is what the dynamic dimension looks like in AutoCAD when the line is being jigged:
A few highlights about the code may be helpful:
• An entity type needs to be specified in the EntityJig derivative, as Line here.
• A DynamicDimensionDataCollection instance needs to be created and initialized in the constructor of the EntityJig.
• The DynamicDimensionDataCollection instance needs to be returned in the GetDynamicDimensionData override.
• The DynamicDimensionDataCollection has to be populated with good DynamicDimensionData elements such as the AlignedDimension as demonstrated and properly indexed.
• Each DynamicDimensionData element should be updated accordingly in the Update() call if its relevant factors have changed.
• The Sampler() override is to acquire input for line points in a certain order.
• 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.
• The keywords can be added easily through the Keywords collection of the JigPromptPointOptions or other similar prompt options objects.
• Please do not forget to handle the cancel/escape circumstance as demonstrated.
• The Update() override is to update the point properties of the line in the same order as set in the Sampler().
• The Editor.Draw() is the power to fire the jig. If two properties need to be set, the jig needs to be fired off twice. That is why a while loop is used.
• The while loop needs to think about the PromptStatus.Keyword case of the PromptResult after each Jig Drag.
• Only after the jig succeeds should the circle be added to the database to avoid database corruption.