Exemple #1
0
        private void Init()
        {
            if (!init && !disposed && !Disposing && !IsDesigner)
            {
                extents = new Extents3d();

                Autodesk.AutoCAD.GraphicsSystem.Manager gsm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.GraphicsManager;

                Autodesk.AutoCAD.GraphicsSystem.KernelDescriptor descriptor = new Autodesk.AutoCAD.GraphicsSystem.KernelDescriptor();
                descriptor.addRequirement(Autodesk.AutoCAD.UniqueString.Intern("3D Drawing"));
                Autodesk.AutoCAD.GraphicsSystem.GraphicsKernel kernel = Autodesk.AutoCAD.GraphicsSystem.Manager.AcquireGraphicsKernel(descriptor);

                device = gsm.CreateAutoCADOffScreenDevice(kernel);
                device.DeviceRenderType = Autodesk.AutoCAD.GraphicsSystem.RendererType.Default;
                device.BackgroundColor  = BackColor;

                view             = new Autodesk.AutoCAD.GraphicsSystem.View();
                view.VisualStyle = new Autodesk.AutoCAD.GraphicsInterface.VisualStyle(Autodesk.AutoCAD.GraphicsInterface.VisualStyleType.Wireframe2D);
                model            = gsm.CreateAutoCADModel(kernel);

                device.Add(view);

                init = true;
            }
        }
Exemple #2
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (device != null)
                {
                    device.EraseAll();
                }
                if (view != null)
                {
                    view.EraseAll();
                    view.Dispose();
                    view = null;
                }
                if (model != null)
                {
                    model.Dispose();
                    model = null;
                }
                if (device != null)
                {
                    device.Dispose();
                    device = null;
                }

                init     = false;
                disposed = true;
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Exemple #3
0
        public static Bitmap GetBitmap(Database db, ObjectIdCollection objIdColl)
        {
            using (db)
            {
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        Manager manager = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.GraphicsManager;
                        Device  device  = manager.CreateAutoCADOffScreenDevice();
                        using (device)
                        {
                            device.OnSize(new System.Drawing.Size(100, 100));
                            Autodesk.AutoCAD.GraphicsSystem.Model model = manager.CreateAutoCADModel();
                            using (model)
                            {
                                double dMinX = 0, dMinY = 0, dMinZ = 0;
                                double dMaxX = 0, dMaxY = 0, dMaxZ = 0;

                                bool isUnstarted = true;
                                Autodesk.AutoCAD.GraphicsSystem.View view = new Autodesk.AutoCAD.GraphicsSystem.View();
                                foreach (ObjectId objId in objIdColl)
                                {
                                    // será usado pra definir limites para criar bitmap
                                    Entity ent = trans.GetObject(objId, OpenMode.ForWrite) as Entity;
                                    //Min Point
                                    if (ent.GeometricExtents.MinPoint.X < dMinX || isUnstarted)
                                    {
                                        dMinX = ent.GeometricExtents.MinPoint.X;
                                    }
                                    if (ent.GeometricExtents.MinPoint.Y < dMinY || isUnstarted)
                                    {
                                        dMinY = ent.GeometricExtents.MinPoint.Y;
                                    }
                                    if (ent.GeometricExtents.MinPoint.Z < dMinZ || isUnstarted)
                                    {
                                        dMinZ = ent.GeometricExtents.MinPoint.Z;
                                    }

                                    //Max Point
                                    if (ent.GeometricExtents.MaxPoint.X > dMaxX || isUnstarted)
                                    {
                                        dMaxX = ent.GeometricExtents.MaxPoint.X;
                                    }
                                    if (ent.GeometricExtents.MaxPoint.Y > dMaxY || isUnstarted)
                                    {
                                        dMaxY = ent.GeometricExtents.MaxPoint.Y;
                                    }
                                    if (ent.GeometricExtents.MaxPoint.Z > dMaxZ || isUnstarted)
                                    {
                                        dMaxZ = ent.GeometricExtents.MaxPoint.Z;
                                    }

                                    isUnstarted = false;
                                    view.Add(ent, model);
                                }

                                Point3d p3dLeftLower = new Point3d(dMinX, dMinY, dMinZ);
                                Point3d p3dRightTop  = new Point3d(dMaxX, dMaxY, dMaxZ);
                                device.Add(view);

                                view.ZoomExtents(p3dLeftLower, p3dRightTop);
                                System.Drawing.Rectangle rect = new Rectangle();// view.Viewport;

                                return(view.GetSnapshot(rect));
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        trans.Abort();
                        return(null);
                    }
                }
            }
        }
Exemple #4
0
        private void Init()
        {
            if (!init && !disposed && !Disposing && !IsDesigner)
            {
                extents = new Extents3d();

                Autodesk.AutoCAD.GraphicsSystem.Manager gsm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.GraphicsManager;
            #if REBARPOS2015
                Autodesk.AutoCAD.GraphicsSystem.KernelDescriptor descriptor = new Autodesk.AutoCAD.GraphicsSystem.KernelDescriptor();
                descriptor.addRequirement(Autodesk.AutoCAD.UniqueString.Intern("3D Drawing"));
                Autodesk.AutoCAD.GraphicsSystem.GraphicsKernel kernel = Autodesk.AutoCAD.GraphicsSystem.Manager.AcquireGraphicsKernel(descriptor);

                device = gsm.CreateAutoCADDevice(kernel, this.Handle);
                device.DeviceRenderType = RendererType.Default;
                device.BackgroundColor = BackColor;

                view = new Autodesk.AutoCAD.GraphicsSystem.View();
                view.VisualStyle = new Autodesk.AutoCAD.GraphicsInterface.VisualStyle(Autodesk.AutoCAD.GraphicsInterface.VisualStyleType.Wireframe2D);

                model = gsm.CreateAutoCADModel(kernel);
            #elif REBARPOS2013
                device = gsm.CreateAutoCADDevice(this.Handle);
                device.DeviceRenderType = RendererType.Default;
                device.BackgroundColor = BackColor;

                view = new Autodesk.AutoCAD.GraphicsSystem.View();
                view.VisualStyle = new Autodesk.AutoCAD.GraphicsInterface.VisualStyle(Autodesk.AutoCAD.GraphicsInterface.VisualStyleType.Wireframe2D);

                model = gsm.CreateAutoCADModel();
            #elif REBARPOS2010
                device = gsm.CreateAutoCADDevice(this.Handle);
                device.DeviceRenderType = RendererType.Default;
                device.BackgroundColor = BackColor;

                view = new Autodesk.AutoCAD.GraphicsSystem.View();
                view.VisualStyle = new Autodesk.AutoCAD.GraphicsInterface.VisualStyle(Autodesk.AutoCAD.GraphicsInterface.VisualStyleType.Wireframe2D);

                model = gsm.CreateAutoCADModel();
            #endif

                device.Add(view);
                device.Update();

                init = true;
            }
        }
Exemple #5
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (device != null)
                {
                    device.EraseAll();
                }
                if (view != null)
                {
                    view.EraseAll();
                    view.Dispose();
                    view = null;
                }
                if (model != null)
                {
                    model.Dispose();
                    model = null;
                }
                if (device != null)
                {
                    device.Dispose();
                    device = null;
                }

                init = false;
                disposed = true;
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
        public BitmapImage GetBitmap()
        {
            //Suprimido pq tava dando fatal erro quando lia do bloco externo
            //if (_bDbIsInExternalDWG)
            //    db.ReadDwgFile(ArCaRefMgrController.DBPath, FileShare.Read, true, "");
            //else
            try
            {
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                using (Database db = doc.Database)
                {
                    using (Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            Manager manager = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.GraphicsManager;
                            Device  device  = manager.CreateAutoCADOffScreenDevice();
                            using (device)
                            {
                                device.OnSize(new System.Drawing.Size(100, 100));
                                Autodesk.AutoCAD.GraphicsSystem.Model model = manager.CreateAutoCADModel();
                                using (model)
                                {
                                    //Suprimido pq tava dando fatal erro quando lia do bloco externo
                                    //if (rbWhite.IsChecked != true)
                                    //    device.BackgroundColor = System.Drawing.Color.Black;
                                    //else
                                    device.BackgroundColor = System.Drawing.Color.White;

                                    double dMinX = 0, dMinY = 0, dMinZ = 0;
                                    double dMaxX = 0, dMaxY = 0, dMaxZ = 0;

                                    Boolean isUnstarted = true;
                                    Autodesk.AutoCAD.GraphicsSystem.View view = new Autodesk.AutoCAD.GraphicsSystem.View();
                                    ObjectIdCollection objIdColl2             = new ObjectIdCollection();

                                    //As pitombas dos objectsId estao trocando de numero quando eu do Read no DWG, to tendo que lere os Ids no Bloco denovo
                                    if (_bDbIsInExternalDWG)
                                    {
                                        using (Transaction tr = db.TransactionManager.StartTransaction())
                                        {
                                            BlockTable       bt  = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                                            BlockTableRecord btr = tr.GetObject(bt[_objBlockModNew.Name], OpenMode.ForRead) as BlockTableRecord;
                                            foreach (ObjectId entId in btr)
                                            {
                                                objIdColl2.Add(entId);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        objIdColl2 = objIdColl;
                                    }

                                    foreach (ObjectId objId in objIdColl2)
                                    {
                                        // será usado pra definir limites para criar bitmap
                                        using (DocumentLock dl = doc.LockDocument())
                                        {
                                            Entity ent = trans.GetObject(objId, OpenMode.ForRead) as Entity;
                                            //Min Point
                                            if (ent.GeometricExtents.MinPoint.X < dMinX || isUnstarted)
                                            {
                                                dMinX = ent.GeometricExtents.MinPoint.X;
                                            }
                                            if (ent.GeometricExtents.MinPoint.Y < dMinY || isUnstarted)
                                            {
                                                dMinY = ent.GeometricExtents.MinPoint.Y;
                                            }
                                            if (ent.GeometricExtents.MinPoint.Z < dMinZ || isUnstarted)
                                            {
                                                dMinZ = ent.GeometricExtents.MinPoint.Z;
                                            }

                                            //Max Point
                                            if (ent.GeometricExtents.MaxPoint.X > dMaxX || isUnstarted)
                                            {
                                                dMaxX = ent.GeometricExtents.MaxPoint.X;
                                            }
                                            if (ent.GeometricExtents.MaxPoint.Y > dMaxY || isUnstarted)
                                            {
                                                dMaxY = ent.GeometricExtents.MaxPoint.Y;
                                            }
                                            if (ent.GeometricExtents.MaxPoint.Z > dMaxZ || isUnstarted)
                                            {
                                                dMaxZ = ent.GeometricExtents.MaxPoint.Z;
                                            }

                                            isUnstarted = false;
                                            view.Add(ent, model);
                                        }
                                    }

                                    Point3d p3dLeftLower = new Point3d(dMinX, dMinY, dMinZ);
                                    Point3d p3dRightTop  = new Point3d(dMaxX, dMaxY, dMaxZ);
                                    device.Add(view);

                                    view.ZoomExtents(p3dLeftLower, p3dRightTop);
                                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle();// view.Viewport;
                                    bmpPreview = view.GetSnapshot(rect);
                                    return(ArCaUtils.GetBitmapImage(bmpPreview));
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            trans.Abort();
                            return(null);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                return(null);
            }
        }