Hi,
IMO, using .NET as a script langage (calling native AutoCAD commands) is a nonsense.
Even LISP provides much more than this kinf of statements.
Anyway, you can convert your selection set into an ObjectId array:
selection.GetObjectIds
Then, iterate thru this array, get each objectId as entity and use the Clone() method to create a copy, add this copy to the current space (or another BlockTableRecord.
Here's a little example, the "Test" command prompt for a selection, a base point, a second point and calls the CopyMove method to copy the selection set and move the copied entities.
{code}[CommandMethod("Test")]
public void Test()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Matrix3d ucs = ed.CurrentUserCoordinateSystem;
PromptSelectionResult psr = ed.GetSelection();
if (psr.Status != PromptStatus.OK)
return;
PromptPointResult ppr = ed.GetPoint("\nBase point: ");
if (ppr.Status != PromptStatus.OK)
return;
Point3d basePoint = ppr.Value;
PromptPointOptions ppo = new PromptPointOptions("\nSecond point: ");
ppo.BasePoint = basePoint;
ppo.UseBasePoint = true;
ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
return;
Vector3d disp = basePoint.TransformBy(ucs).GetVectorTo(ppr.Value.TransformBy(ucs));
ObjectId[] ss = psr.Value.GetObjectIds();
try
{
CopyMove(ss, disp);
}
catch (System.Exception ex)
{
ed.WriteMessage("Error: " + ex.Message);
}
}
private void CopyMove(ObjectId[] ss, Vector3d disp)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
foreach (ObjectId id in ss)
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite, false);
Entity copiedEnt = (Entity)ent.Clone();
btr.AppendEntity(copiedEnt);
tr.AddNewlyCreatedDBObject(copiedEnt, true);
ent.TransformBy(Matrix3d.Displacement(disp));
}
tr.Commit();
}
}{code}