Yeah.
My code is similar to yours, but i miss some part of code:
DBObject clone = (DBObject)tr.GetObject(id, OpenMode.ForRead, false, true);
Table copytbl = clone as Table;
if (!copytbl.IsWriteEnabled) copytbl.UpgradeOpen();
Point3d pt = new Point3d(0, 0, 0);
copytbl.TransformBy(Matrix3d.Displacement(pt - copytbl.Position));
Now, my solution of this problem (without Editor and choice table, only search):
[CommandMethod("CPTBL")]
public void copyTable()
{
Document document = Application.DocumentManager.MdiActiveDocument;
Database database = document.Database;
Database tempDatabase = loadDWG(@"..\myFile.dwg");
ObjectIdCollection idColl = new ObjectIdCollection();
ObjectId idCopiedTable = ObjectId.Null;
try
{
if (tempDatabase != null)
{
ObjectId idLayout = getLayoutFromDictionary(ref tempDatabase, "Model");
using (Transaction tempTransaction =
tempDatabase.TransactionManager.StartTransaction())
{
BlockTableRecord tempRecord =
tempTransaction.GetObject(idLayout,
OpenMode.ForRead,
false) as BlockTableRecord;
foreach (ObjectId idEntity in tempRecord)
{
Entity entity =
tempTransaction.GetObject(idEntity,
OpenMode.ForRead,
false) as Entity;
Table table = entity as Table;
if (table != null)
{
idCopiedTable = table.ObjectId;
idColl.Add(table.ObjectId);
}
tempTransaction.Commit();
}
}
if (idColl.Count != 0)
{
using (Transaction transact =
database.TransactionManager.StartTransaction())
{
BlockTableRecord record =
transact.GetObject(database.CurrentSpaceId,
OpenMode.ForWrite,
false) as BlockTableRecord;
IdMapping mapping = new IdMapping();
tempDatabase.WblockCloneObjects(idColl,
record.ObjectId,
mapping,
DuplicateRecordCloning.Replace,
false);
foreach (ObjectId idRec in record)
{
Entity entity =
transact.GetObject(idRec,
OpenMode.ForRead,
false) as Entity;
Table table = entity as Table;
if (table != null)
{
idCopiedTable = table.ObjectId;
}
}
Table cloneTable = transact.GetObject(idCopiedTable,
OpenMode.ForRead,
false,
true) as Table;
if (!cloneTable.IsWriteEnabled)
{
cloneTable.UpgradeOpen();
}
Point3d pointInsertion = new Point3d(0, 0, 0);
cloneTable.Position = pointInsertion;
transact.Commit();
}
}
tempDatabase.CloseInput(true);
}
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);
}
}