Hi,
I want to be able to switch two blocks. The user select the first block and then the second block. After that I switch the position and rotation of those two blocks. It's working fine except for the attributes, they stay in place. Is there an easy way to make them follow the new position of the block ? Or I have to find a way to calculate the displacement of the block and apply it to the attributes ?
This is what I have so far, pretty simple :
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();
}
}
}