Im trying to create a function that will behave similar to the Import Layouts from Template command. It should open an external drawing database, and copy all of the layouts into the current drawing, and it works perfectly. The problem is if the command is run again and I try to switch tabs, I get the error attached to this post, any help would be appreciated. A good bit of this code is borrowed from another post, i will try to find it to give credit where credit is due
{code}
DocumentLock oLock = Application.DocumentManager.MdiActiveDocument.LockDocument();
Database dbSource = new Database(false, false);
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = dbSource.TransactionManager.StartTransaction();
try
{
dbSource.ReadDwgFile(fileName, System.IO.FileShare.Read,true, null);
ObjectId idDbdSource = dbSource.LayoutDictionaryId;
DBDictionary dbdLayout = (DBDictionary)trans.GetObject(idDbdSource, OpenMode.ForRead, false, false);
ObjectId idLayout;
ObjectIdCollection idc = new ObjectIdCollection();
foreach (DictionaryEntry deLayout in dbdLayout)
{
if ( deLayout.Key.ToString().ToUpper() != "MODEL")
{
idLayout = (ObjectId) deLayout.Value;
if (!idLayout.IsErased)
{
idc.Add(idLayout);
}
}
}
IdMapping im = new IdMapping();
db.WblockCloneObjects(idc, db.LayoutDictionaryId,im,DuplicateRecordCloning.Ignore,false);
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
MessageBox.Show(ex.ToString(), "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(), "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
trans.Commit();
dbSource.Dispose();
oLock.Dispose();
}
{code}
Edited by: abryanb on Jan 26, 2009 12:16 PM