Here's a start
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof(Iso.IsoRectangle))]
namespace Iso
{
class IsoRectangle
{
[CommandMethod("ir")]
public static void Rectangle()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = HostApplicationServices.WorkingDatabase;
PromptPointOptions ppo = new PromptPointOptions
("\nSpecify first corner point: ");
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) return;
Point3d corner1 = ppr.Value;
RectangleJig Recjig = new RectangleJig(corner1);
if (ed.Drag(Recjig).Status == PromptStatus.Cancel) return;
Polyline pline = Recjig.pline;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject
(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(pline);
tr.AddNewlyCreatedDBObject(pline, true);
tr.Commit();
}
return;
}
public class RectangleJig : EntityJig
{
private Point2d P1, P2, P3, P4;
private Point3d corner1, corner2;
private PromptPointResult pres;
public Polyline pline;
private double tan30 = Math.Tan((30.0 / 180.0) * Math.PI);
public RectangleJig(Point3d _corner1)
: base(new Polyline(3))
{
corner1 = _corner1;
pline = (Polyline)Entity;
pline.SetDatabaseDefaults();
P1 = new Point2d(corner1.X, corner1.Y);
pline.AddVertexAt(0, P1, 0, 0, 0);
pline.AddVertexAt(1, P1, 0, 0, 0);
pline.AddVertexAt(2, P1, 0, 0, 0);
pline.AddVertexAt(3, P1, 0, 0, 0);
pline.Closed = true;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions jigPointOpts = new JigPromptPointOptions
("\nSpecify other corner point");
jigPointOpts.UseBasePoint = true;
jigPointOpts.BasePoint = corner1;
jigPointOpts.UserInputControls = (UserInputControls.Accept3dCoordinates)
| UserInputControls.NullResponseAccepted;
pres = prompts.AcquirePoint(jigPointOpts);
Point3d endPointTemp = pres.Value;
if (endPointTemp != corner2)
{
corner2 = endPointTemp;
}
else
return SamplerStatus.NoChange;
if (pres.Status == PromptStatus.Cancel)
return SamplerStatus.Cancel;
else
return SamplerStatus.OK;
}
protected override bool Update()
{
P3 = new Point2d(corner2.X, corner2.Y);
double y = tan30 * (corner2.X - corner1.X);
P2 = new Point2d(corner2.X, corner1.Y + y);
P4 = new Point2d(corner1.X, corner2.Y - y);
pline.SetPointAt(1, P2);
pline.SetPointAt(2, P3);
pline.SetPointAt(3, P4);
return true;
}
}// end class RectangleJig
} //End class IsoRectangle