== Continuous copy ==
//inspired by Donnia Tabor-Hanson's (CadMama) continuous copy lisp 'cc.lsp'
[CommandMethod("CC")]
public static void ContinuousCopy()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = doc.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
db.CurrentSpaceId,
OpenMode.ForWrite,
false);
using (tr)
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect Object >>");
peo.SetRejectMessage("\nNothing selected >>");
PromptEntityResult res;
res = ed.GetEntity(peo);
if (res.Status != PromptStatus.OK)
return;
Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
if (ent == null)
return;
Point3d pt = res.PickedPoint;
PromptAngleOptions pao =
new PromptAngleOptions("\nSelect angle: ");
PromptDoubleResult ares;
ares = ed.GetAngle(pao);
if (ares.Status != PromptStatus.OK)
return;
double ang = ares.Value;
PromptDistanceOptions pdo =
new PromptDistanceOptions("\nEnter a distance >>");
pdo.AllowNone = true;
pdo.UseDefaultValue = true;
pdo.DefaultValue = 12.0;
pdo.Only2d = true;
PromptDoubleResult dres;
dres = ed.GetDistance(pdo);
if (dres.Status != PromptStatus.OK)
return;
double dist = dres.Value;
double step = dist;
PromptKeywordOptions pko = new PromptKeywordOptions("\nCopy or Break out? [Copy/Break]:", "Copy Break");
pko.AllowNone = true;
pko.Keywords.Default = "Copy";
PromptResult kres = ed.GetKeywords(pko);
ed.WriteMessage("\n" + kres.StringResult);
while (kres.StringResult == "Copy")
{
Entity cent =(Entity) ent.Clone() as Entity;
Point3d topt = PolarPoint(pt, ang, dist);
Matrix3d mtx = Matrix3d.Displacement(pt.GetVectorTo(topt));
cent.TransformBy(mtx);
btr.AppendEntity(cent);
tr.AddNewlyCreatedDBObject(cent, true);
db.TransactionManager.QueueForGraphicsFlush();
dist = dist+step;
kres = ed.GetKeywords(pko);
if (kres.StringResult != "Copy") break;
}
tr.Commit();
}
}
// by Tony Tanzillo
public static Point3d PolarPoint(Point3d basepoint, double angle, double distance)
{
return new Point3d(
basepoint.X + (distance * Math.Cos(angle)),
basepoint.Y + (distance * Math.Sin(angle)),
basepoint.Z);
}