Stream(ArrayList data, Manager mgr) { data.Add(new Snoop.Data.ClassSeparator(typeof(Manager))); #if AC2012 data.Add(new Snoop.Data.ObjectUnknown("Display Size", mgr.DisplaySize)); #else data.Add(new Snoop.Data.ObjectUnknown("Display Size", mgr.DeviceIndependentDisplaySize)); #endif KernelDescriptor descriptor = new KernelDescriptor(); descriptor.addRequirement(Autodesk.AutoCAD.UniqueString.Intern("3D Drawing")); GraphicsKernel kernal = Manager.AcquireGraphicsKernel(descriptor); data.Add(new Snoop.Data.Object("Get DB Model", mgr.GetDBModel(kernal))); data.Add(new Snoop.Data.Object("Get GUI Device", mgr.GetGUIDevice(kernal))); }
public static System.Drawing.Image GetBlockImageFromDrawing(string blockName) { System.Drawing.Bitmap blockBmp = null; Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; ObjectId BlockId = ObjectId.Null; using (Transaction nativeTrans = db.TransactionManager.StartTransaction()) { using (BlockTable bt = nativeTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable) { if (bt.Has(blockName)) { BlockId = bt[blockName]; } } } Manager gsm = doc.GraphicsManager; // now set the block sizes to something standard Point2d screenSize = (Point2d)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("SCREENSIZE"); // set up the image sizes int width = (int)screenSize.X; int height = (int)screenSize.Y; // now create an off screen device KernelDescriptor descriptor = new KernelDescriptor(); descriptor.addRequirement(Autodesk.AutoCAD.UniqueString.Intern("3D Drawing")); GraphicsKernel kernal = Manager.AcquireGraphicsKernel(descriptor); using (Device offDevice = gsm.CreateAutoCADOffScreenDevice(kernal)) { // now size the device offDevice.OnSize(new System.Drawing.Size(width, height)); // now create the view using (View view = new View()) { // add the new view object to the device offDevice.Add(view); // update it offDevice.Update(); // ok now create the model using (Model model = gsm.CreateAutoCADModel(kernal)) { using (Transaction nativeTrans = db.TransactionManager.StartTransaction()) { using (BlockTable bt = nativeTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable) { // now iterate through our block tables foreach (ObjectId id in bt) { if (id == BlockId) { // open the btr for read using (BlockTableRecord btr = nativeTrans.GetObject(id, OpenMode.ForRead) as BlockTableRecord) { // add the btr to the view view.Add(btr, model); try { // get the extents of the btr Extents3d extents = new Extents3d(); Vector3d buffer = new Vector3d(2, 2, 0); extents.AddBlockExtents(btr); _extMin = extents.MinPoint; _extMax = extents.MaxPoint; SetViewTo(view, db); // snap the image System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height); blockBmp = view.GetSnapshot(rect); } catch { } // reset the view for the next iteration view.EraseAll(); } } } } } } offDevice.EraseAll(); } } return(blockBmp); }