Database.ResolveXrefs(false, true); perhaps...?
Thanks for the suggestion. Tried it. Still not in xref palette.
Interesting, it works just fine. Behaves like an xref should.
When I examine xrefs using the -xref command it is listed as an attach type xref.
Could it be that it's just the palette that doesn't recognize it?
Another thing that bothers me is that AttachXref method returns an ObjectID but I don't see where any entity gets added to the blocktablerecord.
On the other hand when you insert an instance of the xref (as a blockreference) that entity is added to the blocktablerecord.
Xrefs have a definition like blockrefs do.
It is the xref definition that isn't showing up in the palette. Maybe I need to save or record the definition in some other way.
Autodesk.AutoCAD.ApplicationServices.Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
ObjectId oid = ObjectId.Null;
ObjectId bid = ObjectId.Null;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
using (DocumentLock dlock = doc.LockDocument())
{
try
{
oid = db.AttachXref(finFile, "Finishes");
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForWrite);
//BlockTableRecord xbt = (BlockTableRecord)trans.GetObject(oid, OpenMode.ForRead);
//Database xdb = xbt.GetXrefDatabase(true);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
BlockReference bref = new BlockReference(new Autodesk.AutoCAD.Geometry.Point3d(1046, 0, 0), oid);
bid = btr.AppendEntity(bref);
trans.AddNewlyCreatedDBObject(bref, true);
trans.Commit();
db.ResolveXrefs(false, true);
}
catch { }
}
}