Am I completely missing something that is staring me straight in the face?
The problem and you might have to regen to get it show both, but this will update the block's clone and original block.
The code is a basic example and it is like the ObjectIds are not being translated correctly.
I have even broke it up into 2 commands to do the changing of the Clone Entities to see if the translating was done after the transaction commited but they still both change.
This should deepclone a BlockTableRecord and name it 'OriginalName' + 'COPY' then change all the entities in the new BlockTableRecord to red but also changes the original?
?
It is like the entities in the newly cloned BlockTableRecord and the original BlockTableRecord are pointing to same object, and the ids were not translated.
[CommandMethod("WTF")]
public void WTF()
{
using (Transaction trx = db.TransactionManager.StartTransaction())
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect Block Reference: ");
peo.SetRejectMessage("\n That was not a Block Reference");
peo.AddAllowedClass(typeof(BlockReference), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
{
return;
}
BlockReference bref = (BlockReference)trx.GetObject(per.ObjectId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trx.GetObject(bref.BlockTableRecord, OpenMode.ForRead);
if (btr.Name.EndsWith("COPY"))
{
return;
}
string btrName = btr.Name "COPY";
BlockTable bt = (BlockTable)trx.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord newBtr = null;
if (bt.Has(btrName))
{
newBtr = (BlockTableRecord)trx.GetObject(bt[btrName], OpenMode.ForRead);
}
else
{
bt.UpgradeOpen();
//IdMapping idMap = new IdMapping();
//newBtr = (BlockTableRecord)btr.DeepClone(bt, idMap, false);
newBtr = (BlockTableRecord)btr.DeepClone(bt, new IdMapping(), true);
newBtr.Name = btrName;
bt.Add(newBtr);
trx.AddNewlyCreatedDBObject(newBtr, true);
foreach (ObjectId id in newBtr)
{
Entity ent = trx.GetObject(id, OpenMode.ForRead) as Entity;
if (ent == null)
{
continue;
}
ent.UpgradeOpen();
ent.ColorIndex = 1;
}
}
bref.UpgradeOpen();
bref.BlockTableRecord = newBtr.ObjectId;
trx.Commit();
}
}