public void CopyObjectsBetweenDatabases(ObjectIdCollection acObjIdColl, string dwgFilename)
{
//ObjectIdCollection acObjIdColl = new ObjectIdCollection();
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Change the file and path to match a drawing template on your workstation
string sLocalRoot = Application.GetSystemVariable("LOCALROOTPREFIX") as string;
string sTemplatePath = sLocalRoot + "Template\\acadiso.dwt";
// Create a new drawing to copy the objects to
DocumentCollection acDocMgr = Application.DocumentManager;
Document acNewDoc = acDocMgr.Add(sTemplatePath);
Database acDbNewDoc = acNewDoc.Database;
// Lock the new document
using (DocumentLock acLckDoc = acNewDoc.LockDocument())
{
// Start a transaction in the new database
using (Transaction acTrans = acDbNewDoc.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTblNewDoc;
acBlkTblNewDoc = acTrans.GetObject(acDbNewDoc.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for read
BlockTableRecord acBlkTblRecNewDoc;
acBlkTblRecNewDoc = acTrans.GetObject(acBlkTblNewDoc[BlockTableRecord.ModelSpace],
OpenMode.ForRead) as BlockTableRecord;
// Clone the objects to the new database
IdMapping acIdMap = new IdMapping();
acCurDb.WblockCloneObjects(acObjIdColl, acBlkTblRecNewDoc.ObjectId, acIdMap,
DuplicateRecordCloning.Ignore, false);
ZoomExtCmd();
// Save the copied objects to the database
acTrans.Commit();
}
// Unlock the document
}
// Set the new document current
//acDocMgr.MdiActiveDocument = acNewDoc;
dynamic acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
acadApp.ZoomExtents();
//Active.Document.SendStringToExecute("_.zoom _all ", true, true, false);
acDbNewDoc.SaveAs(dwgFilename, DwgVersion.Current);
acNewDoc.CloseAndSave(dwgFilename);
}
public void ZoomExtCmd()
{
var ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.Command("_.zoom", "_extents");
}