[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();
}
}
Okay I think I need to be using
DeepCloneObjects
...
let newBtrId =
if bt.Has newBtrName then
bt.[newBtrName]
else
bt.UpgradeOpen()
let newBtr = btr.Clone() :?> BlockTableRecord
newBtr.Name <- newBtrName
let newBtrIdTmp = bt.Add newBtr
tr.AddNewlyCreatedDBObject(newBtr, true)
let oidc = new ObjectIdCollection()
for oid in btr do
oidc.Add oid |> ignore
let idMap = new IdMapping()
db.DeepCloneObjects(oidc, newBtrIdTmp, idMap, false)
for o in idMap do
let idPair = o :?> IdPair
if idPair.IsPrimary then
match tr.GetObject(idPair.Value, OpenMode.ForWrite) with
| :? Entity as ent ->
ent.ColorIndex <- 1
| _ -> ()
newBtrIdTmp
bref.UpgradeOpen()
bref.BlockTableRecord <- newBtrId
...
Thanks Byrco,Got a PM about this and sorry for the mess but maybe this help out.
That fix it.
If anyonre needs me post the updated code I will,
I have not cleaned it up since it was for example but if anyone asks I will take the minute to clean up and post