Hi
A little sample I wrote while I was learning about Jigs. It mimics tha AutoCAD command Arc option 3 points.
Look at the Update method.
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace Arc3Points
{
public class ArcJigSample
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
private const double pi = 3.141592653589793;
class ArcJig : EntityJig
{
Arc _arc;
Point3d _dragPoint;
Point3d _firstPoint;
Point3d _secondPoint;
public ArcJig(Arc arc, Point3d dragPoint, Point3d firstPoint, Point3d secondPoint)
: base(arc)
{
_arc = arc;
_dragPoint = dragPoint;
_firstPoint = firstPoint;
_secondPoint = secondPoint;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions jppo = new JigPromptPointOptions("\nSpecify the third point: ");
jppo.UserInputControls = (UserInputControls.Accept3dCoordinates);
PromptPointResult ppr = prompts.AcquirePoint(jppo);
if (ppr.Status == PromptStatus.OK)
{
if (ppr.Value.IsEqualTo(_dragPoint))
return SamplerStatus.NoChange;
else
{
_dragPoint = ppr.Value;
return SamplerStatus.OK;
}
}
return SamplerStatus.Cancel;
}
protected override bool Update()
{
CircularArc3d cArc = new CircularArc3d(_firstPoint, _secondPoint, _dragPoint);
Point3d cen = cArc.Center;
_arc.Center = cen;
_arc.Radius = cArc.Radius;
Vector3d vec1 = _firstPoint.GetVectorTo(_secondPoint);
Vector3d vec2 = _secondPoint.GetVectorTo(_dragPoint);
Vector3d norm = cArc.Normal;
_arc.Normal = norm;
Vector3d vecX = Vector3d.XAxis.TransformBy(Matrix3d.PlaneToWorld(norm));
double angToFirst = vecX.GetAngleTo(cen.GetVectorTo(_firstPoint), norm);
double angToDrag = vecX.GetAngleTo(cen.GetVectorTo(_dragPoint), norm);
if (vec1.GetAngleTo(vec2, norm) > pi)
{
_arc.StartAngle = angToDrag;
_arc.EndAngle = angToFirst;
}
else
{
_arc.StartAngle = angToFirst;
_arc.EndAngle = angToDrag;
}
return true;
}
}
[CommandMethod("A3P")]
public void DrawArc()
{
Point3d pt1;
Point3d pt2;
PromptPointOptions ppo = new PromptPointOptions("\nSpecifiy the first point: ");
ppo.AllowNone = false;
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status == PromptStatus.OK)
{
pt1 = ppr.Value;
ppo.Message = "\nSpecify the second point: ";
ppo.AllowNone = false;
ppo.BasePoint = pt1;
ppo.UseBasePoint = true;
ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) return;
try
{
Matrix3d curUCS = ed.CurrentUserCoordinateSystem;
pt2 = ppr.Value;
pt1 = pt1.TransformBy(curUCS);
pt2 = pt2.TransformBy(curUCS);
Vector3d vec = pt1.GetVectorTo(pt2) / 2;
using (Arc ghost = new Arc(pt1 + vec, vec.Length, 0.0, pi))
{
ArcJig jig = new ArcJig(ghost, pt2, pt1, pt2);
PromptResult res = ed.Drag(jig);
if (res.Status != PromptStatus.OK) return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(ghost);
tr.AddNewlyCreatedDBObject(ghost, true);
tr.Commit();
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage("\nError: " + ex.Message);
}
}
}
}
}