Thank you for your posts and recommendations. I have switched my code to open the a separate drawing and copy the blocks over. From there I was doing to load a block at a time into model space from the new drawing, take my screenshot, clear the modelspace block table and then move onto the next block. Does this even sound feasible?
I am currently hitting an error with my code...
"Operation is not valid due to the current state of the object."
Here is the latest revision of my code thus far.
DocumentCollection dm = Application.DocumentManager;
Database sourceDB = dm.MdiActiveDocument.Database;
try
{
// Collect the objectID's to be copied
ObjectIdCollection blockIds = new ObjectIdCollection();
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sourceDB.TransactionManager;
using (Transaction tran = tm.StartTransaction())
{
BlockTable bt = (BlockTable)tm.GetObject(sourceDB.BlockTableId, OpenMode.ForRead, false);
foreach (ObjectId btrId in bt)
{
BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId, OpenMode.ForRead, false);
if (!btr.IsAnonymous && !btr.IsLayout)
blockIds.Add(btrId);
btr.Dispose();
}
}
// Create the new Drawing to put the objects in
Document acTempDoc = dm.Add("acad.dwt");
acTempDoc.LockDocument();
Database destDB = acTempDoc.Database;
// Put the objects in the new drawing
IdMapping mapping = new IdMapping();
sourceDB.WblockCloneObjects(blockIds, destDB.BlockTableId, mapping, DuplicateRecordCloning.Replace, false);
// Draw the a block on the new drawing
Autodesk.AutoCAD.DatabaseServices.TransactionManager tmDest = destDB.TransactionManager;
using (Transaction tranDest = tmDest.StartTransaction())
{
BlockTable bt = (BlockTable)tranDest.GetObject(destDB.BlockTableId, OpenMode.ForRead);
foreach (ObjectId btrid in bt)
{
BlockTableRecord btr = (BlockTableRecord)tranDest.GetObject(btrid, OpenMode.ForRead);
foreach (ObjectId id in btr)
{
BlockReference brMS = new BlockReference(Point3d.Origin, id);
BlockTableRecord ms = (BlockTableRecord)tranDest.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
ms.AppendEntity(brMS);
tranDest.AddNewlyCreatedDBObject(brMS, true);
tranDest.Commit();
}
}
}
}
catch (System.Exception ex)
{
Application.ShowAlertDialog(ex.Message);
}