Well this took a while, I was messing with xrecords when I shouldn't have bothered. Tim I don't know lisp but it looks like your lisp is looking for a dictionary within a dictionary (rather than an xrecord within a dictionary). I still can't figure out how to copyfrom or make the new dictionary=the old dictionary (this doesn't work maybe because the old dictionary is being deleted), there should be a more direct way than below.
[CommandMethod("OVERLAY")]
public void attachTooverlay()
{
Document doc =acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect xref: ");
peo.SetRejectMessage("Must be an x-ref");
peo.AddAllowedClass(typeof(BlockReference), true);
PromptEntityResult res = ed.GetEntity(peo);
if (res.Status != PromptStatus.OK) return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockReference br = tr.GetObject
(res.ObjectId, OpenMode.ForWrite) as BlockReference;
BlockTableRecord btr = tr.GetObject
(br.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
if (!btr.IsFromExternalReference)
{
MessageBox.Show("not an x-ref");
return;
}
if (btr.IsFromOverlayReference) return;
XrefStatus xstatus=btr.XrefStatus;
BlockScaling bs=btr.BlockScaling;
bool bLoaded=btr.IsUnloaded;
UnitsValue uv = btr.Units;
string fileName =btr.PathName;
string blockName = btr.Name;
ObjectIdCollection ids = btr.GetBlockReferenceIds(true, true);
int ct = ids.Count;
object[][] ob =new object[ct][];
for (int i = 0; i < ct; i++)
{
BlockReference xref = tr.GetObject
(ids[i], OpenMode.ForRead) as BlockReference;
BlockTableRecord xtr = tr.GetObject(
xref.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
ob[i] = new object[8];
ob[i][0] = xref.Position;
ob[i][ 1] = xref.Rotation;
ob[i][ 2] = xref.Layer;
ob[i][ 3] = xref.ColorIndex;
ob[i][ 4] = xref.ScaleFactors;
ob[i][5] = xref.OwnerId;
ob[i][6] = xref.Normal;
ob[i][7] = xref.ExtensionDictionary;
ObjectId xclipId = xref.ExtensionDictionary;
xref.UpgradeOpen();
xref.Erase();
xref.DowngradeOpen();
}
db.DetachXref(btr.Id);
ObjectId xrefId = db.OverlayXref(fileName, blockName);
for (int i = 0; i < ct; i++)
{
btr = (BlockTableRecord)tr.GetObject(xrefId, OpenMode.ForWrite);
BlockTableRecord space = (BlockTableRecord)tr.GetObject(
(ObjectId)ob[i][5], OpenMode.ForWrite);
br = new BlockReference((Point3d)ob[i][0], btr.ObjectId);
br.Rotation = (double)ob[i][1];
br.Layer = (string)ob[i][2];
br.ColorIndex = (int)ob[i][3];
br.ScaleFactors=(Scale3d) ob[i][4];
br.Normal = (Vector3d)ob[i][6];
ObjectId xclipId =(ObjectId) ob[i][7];
space.AppendEntity(br);
tr.AddNewlyCreatedDBObject(br, true);
if (! xclipId.IsNull)
{
br.CreateExtensionDictionary();
DBDictionary XclipDic = tr.GetObject
(br.ExtensionDictionary,OpenMode.ForWrite) as DBDictionary;
DBDictionary dic = tr.GetObject(xclipId, OpenMode.ForRead) as DBDictionary;
DBDictionary FilterDic = tr.GetObject
(dic.GetAt("ACAD_FILTER"), OpenMode.ForRead) as DBDictionary;
DBDictionary nd = new DBDictionary();
foreach (DictionaryEntry de in FilterDic)
{
nd.SetAt((string)de.Key, tr.GetObject((ObjectId) de.Value,OpenMode.ForWrite ) as DBObject);
}
XclipDic.SetAt("ACAD_FILTER", nd);
tr.AddNewlyCreatedDBObject(nd, true);
}
}
db.ResolveXrefs(true, true);
tr.Commit();
}
}//end attachTooverlay