private void btnCopyBlk_Click(object sender, EventArgs e)
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions peo1 = new PromptEntityOptions("Select first block: \n");
peo1.SetRejectMessage(MB.rmM.GetString("SelNoBlock"));
peo1.AllowNone = false;
peo1.AddAllowedClass(typeof(BlockReference), false);
PromptEntityResult per1 = ed.GetEntity(peo1);
if (per1.Status != PromptStatus.OK) return;
if (per1.ObjectId == ObjectId.Null) return;
PromptEntityOptions peo2 = new PromptEntityOptions("Select second block: \n");
peo2.SetRejectMessage(MB.rmM.GetString("SelNoBlock"));
peo2.AllowNone = false;
peo2.AddAllowedClass(typeof(BlockReference), false);
PromptEntityResult per2 = ed.GetEntity(peo2);
if (per2.Status != PromptStatus.OK) return;
if (per2.ObjectId == ObjectId.Null) return;
using (doc.LockDocument())
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockReference br1 = (BlockReference)tr.GetObject(per1.ObjectId, OpenMode.ForWrite);
BlockReference br2 = (BlockReference)tr.GetObject(per2.ObjectId, OpenMode.ForWrite);
Point3d position1 = br1.Position;
Point3d position2 = br2.Position;
double rotation1 = br1.Rotation;
double rotation2 = br2.Rotation;
br1.Position = position2;
br2.Position = position1;
br1.Rotation = rotation2;
br2.Rotation = rotation1;
tr.Commit();
}
}
}