private void lvBlocks_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            //verifica se o duplo clique foi no scroll bar
            ScrollBar objScroll = ArCaUtils.FindAncestor <ScrollBar>(e.OriginalSource as DependencyObject);

            if (objScroll != null)
            {
                return; //clicou no scroll - não faz nada
            }
            //localiza o item selecionado
            ListViewItem objItem = ArCaUtils.FindAncestor <ListViewItem>(e.OriginalSource as DependencyObject);

            if (objItem == null)
            {
                return;
            }

            //Get BlockModel
            BlockModel objBlockModel = objItem.DataContext as BlockModel;

            //TODO--------Remover in the future-------------
            //Gambiarra pra resolver o Problema com o Focus da Pallet
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            if (!ArCaCommands._PalletRefMgr.Dock.Equals(DockSides.None))
            {
                ed.GetPoint("");
            }
            //----------------------------------------------

            //Insert Block
            ArCaCommands.InsestBlock(objBlockModel);
        }
        static private void addRefMgr(RibbonTab ribTab)
        {
            //create the panel source
            Autodesk.Windows.RibbonPanelSource ribSourcePanel = new RibbonPanelSource();
            ribSourcePanel.Title = "References";
            //now the panel
            RibbonPanel ribPanel = new RibbonPanel();

            ribPanel.Source = ribSourcePanel;
            ribTab.Panels.Add(ribPanel);
            //create button Refm
            Autodesk.Windows.RibbonButton ribButton1 = new RibbonButton();
            ribButton1.Orientation = System.Windows.Controls.Orientation.Vertical;
            BitmapImage bmpI = ArCaUtils.GetBitmapImage(ArCaManaged.Properties.Resources.RefMgr);

            ribButton1.LargeImage       = bmpI;
            ribButton1.Image            = bmpI;
            ribButton1.Size             = RibbonItemSize.Large;
            ribButton1.Text             = "Reference Manager";
            ribButton1.ShowText         = true;
            ribButton1.CommandParameter = "refm ";
            ribButton1.ShowImage        = true;
            ribButton1.CommandHandler   = new AdskCommandHandler();
            ribSourcePanel.Items.Add(ribButton1);
        }
        static public BitmapImage GetThumbnail(string blockName)
        {
            Bitmap bmpPreview;

            using (Database dbRef = new Database(false, true))
            {
                // Read the DWG
                dbRef.ReadDwgFile(DBPath, FileShare.Read, true, "");
                using (Transaction trans = dbRef.TransactionManager.StartTransaction())
                {
                    BlockTable       bt        = trans.GetObject(dbRef.BlockTableId, OpenMode.ForRead) as BlockTable;
                    BlockTableRecord BlcTabRec = trans.GetObject(bt[blockName], OpenMode.ForRead) as BlockTableRecord;
                    bmpPreview = BlcTabRec.PreviewIcon;
                }
            }
            return(ArCaUtils.GetBitmapImage(bmpPreview));
        }
Example #4
0
        public DWGFileModel(string sFilePath)
        {
            _sFilePath = sFilePath;
            _sFileName = Path.GetFileNameWithoutExtension(sFilePath);
            _sFileDate = String.Format("{0:MM/dd/yyyy}", File.GetLastWriteTime(sFilePath));
            _sFileSize = String.Format("{0:MM/dd/yyyy}", File.GetLastWriteTime(sFilePath));
            FileInfo fi = new FileInfo(sFilePath);

            _sFileSize       = (fi.Length / 1024).ToString() + " KB";
            _bIsChanged      = false;
            _sMessageProcess = "Unprocessed";

            using (Database db = new Database(false, true))
            {
                // Read the DWG
                db.ReadDwgFile(sFilePath, FileShare.Read, true, "");
                _btmImage = ArCaUtils.GetBitmapImage(db.ThumbnailBitmap);
            }
        }
        static private void addCusEnt(RibbonTab ribTab)
        {
            //create the panel source
            Autodesk.Windows.RibbonPanelSource ribSourcePanel = new RibbonPanelSource();
            ribSourcePanel.Title = "WT-Tools Entities";
            //now the panel
            RibbonPanel ribPanel = new RibbonPanel();

            ribPanel.Source = ribSourcePanel;
            ribTab.Panels.Add(ribPanel);

            //create button
            Autodesk.Windows.RibbonButton ribButtonGrating = new RibbonButton();
            ribButtonGrating.Orientation = System.Windows.Controls.Orientation.Vertical;
            BitmapImage bmpI = ArCaUtils.GetBitmapImage(ArCaManaged.Properties.Resources.grating);

            ribButtonGrating.LargeImage       = bmpI;
            ribButtonGrating.Image            = bmpI;
            ribButtonGrating.Size             = RibbonItemSize.Large;
            ribButtonGrating.Text             = "Grating";
            ribButtonGrating.ShowText         = true;
            ribButtonGrating.CommandParameter = "grating ";
            ribButtonGrating.CommandHandler   = new AdskCommandHandler();

            //create button
            Autodesk.Windows.RibbonButton ribButtonRamp = new RibbonButton();
            ribButtonRamp.Orientation = System.Windows.Controls.Orientation.Vertical;
            BitmapImage bmpIRamp = ArCaUtils.GetBitmapImage(ArCaManaged.Properties.Resources.Ramp);

            ribButtonRamp.LargeImage       = bmpIRamp;
            ribButtonRamp.Image            = bmpIRamp;
            ribButtonRamp.Size             = RibbonItemSize.Large;
            ribButtonRamp.Text             = "Ramp";
            ribButtonRamp.ShowText         = true;
            ribButtonRamp.CommandParameter = "ramp ";
            ribButtonRamp.CommandHandler   = new AdskCommandHandler();

            //create button
            //create a Ribbon List Button
            Autodesk.Windows.RibbonSplitButton ribListBtn = new RibbonSplitButton();

            Autodesk.Windows.RibbonButton ribButtonQuota = new RibbonButton();
            ribButtonQuota.Orientation = System.Windows.Controls.Orientation.Vertical;
            BitmapImage bmpIQuota = ArCaUtils.GetBitmapImage(ArCaManaged.Properties.Resources.Quota);

            ribButtonQuota.LargeImage       = bmpIQuota;
            ribButtonQuota.Image            = bmpIQuota;
            ribButtonQuota.Size             = RibbonItemSize.Large;
            ribButtonQuota.Text             = "Arrow";
            ribButtonQuota.ShowText         = true;
            ribButtonQuota.CommandParameter = "quota arrow ";
            ribButtonQuota.CommandHandler   = new AdskCommandHandler();

            Autodesk.Windows.RibbonButton ribButtonQuota_Leader = new RibbonButton();
            ribButtonQuota_Leader.Orientation = System.Windows.Controls.Orientation.Vertical;
            BitmapImage bmpIQuota_Leader = ArCaUtils.GetBitmapImage(ArCaManaged.Properties.Resources.Quota_Leader);

            ribButtonQuota_Leader.LargeImage       = bmpIQuota_Leader;
            ribButtonQuota_Leader.Image            = bmpIQuota;
            ribButtonQuota_Leader.Size             = RibbonItemSize.Large;
            ribButtonQuota_Leader.Text             = "Leader";
            ribButtonQuota_Leader.ShowText         = true;
            ribButtonQuota_Leader.CommandParameter = "quota leader ";
            ribButtonQuota_Leader.CommandHandler   = new AdskCommandHandler();

            Autodesk.Windows.RibbonButton ribButtonQuota_Plane = new RibbonButton();
            ribButtonQuota_Leader.Orientation = System.Windows.Controls.Orientation.Vertical;
            BitmapImage bmpIQuota_Plane = ArCaUtils.GetBitmapImage(ArCaManaged.Properties.Resources.Quota_Plane);

            ribButtonQuota_Plane.LargeImage       = bmpIQuota_Plane;
            ribButtonQuota_Plane.Image            = bmpIQuota;
            ribButtonQuota_Plane.Size             = RibbonItemSize.Large;
            ribButtonQuota_Plane.Text             = "Plane";
            ribButtonQuota_Plane.ShowText         = true;
            ribButtonQuota_Plane.CommandParameter = "quota plane ";
            ribButtonQuota_Plane.CommandHandler   = new AdskCommandHandler();

            ribListBtn.Text     = "Quota";
            ribListBtn.Size     = RibbonItemSize.Large;
            ribListBtn.ShowText = true;
            ribListBtn.Items.Add(ribButtonQuota);
            ribListBtn.Items.Add(ribButtonQuota_Leader);
            ribListBtn.Items.Add(ribButtonQuota_Plane);

            ribSourcePanel.Items.Add(ribButtonGrating);
            ribSourcePanel.Items.Add(ribButtonRamp);
            ribSourcePanel.Items.Add(ribListBtn);
        }
        public static void LoadProcedures()
        {
            _ListProcedures.Clear();

            #region Purge

            if (_DWGCollection.Purge)
            {
                _ListProcedures.Add(new Procedure(delegate(Database db, Transaction tr, DWGFileModel objDWG)
                {
                    // Create the list of objects to "purge"
                    ObjectIdCollection idsToPurge = ArCaUtils.GetObjIdNonGrafical(db);

                    // Call the Purge function to filter the list
                    db.Purge(idsToPurge);

                    if (idsToPurge.Count != 0)
                    {
                        // Erase each of the objects we've been
                        // allowed to
                        foreach (ObjectId id in idsToPurge)
                        {
                            DBObject obj = tr.GetObject(id, OpenMode.ForWrite);
                            obj.Erase();
                        }

                        //Was Changed
                        objDWG.IsChanged = true;
                    }
                }));
            }

            #endregion

            #region Lock View Ports

            if (_DWGCollection.LockViewPorts)
            {
                _ListProcedures.Add(new Procedure(delegate(Database db, Transaction tr, DWGFileModel objDWG)
                {
                    //Block Table
                    BlockTable btBlock = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                    foreach (ObjectId btrId in btBlock)
                    {
                        BlockTableRecord ltr = tr.GetObject(btrId, OpenMode.ForWrite) as BlockTableRecord;
                        foreach (ObjectId acObjId in ltr)
                        {
                            if (acObjId.ObjectClass.DxfName == "VIEWPORT")
                            {
                                Viewport vp = tr.GetObject(acObjId, OpenMode.ForWrite) as Viewport;
                                vp.Locked   = true;
                                //Was Changed
                                objDWG.IsChanged = true;
                            }
                        }
                    }
                }));
            }

            if (_DWGCollection.ZoomExtents)
            {
                _ListProcedures.Add(new Procedure(delegate(Database db, Transaction tr, DWGFileModel objDWG)
                {
                    //Model
                    ViewportTable vpt = tr.GetObject(db.ViewportTableId, OpenMode.ForWrite) as ViewportTable;
                    foreach (ObjectId btrId in vpt)
                    {
                        ViewportTableRecord vptrec = tr.GetObject(btrId, OpenMode.ForWrite) as ViewportTableRecord;
                        SetViewportToExtents(db, vptrec);
                    }

                    //Paper Spaces
                    BlockTable btBlock = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                    foreach (ObjectId btrId in btBlock)
                    {
                        BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForWrite) as BlockTableRecord;

                        if (!btr.Name.StartsWith("*Paper_Space"))
                        {
                            continue;
                        }

                        //Retrieve paper space viewport (viewport with the lowest handle)
                        Viewport paperVp  = null;
                        long lowestHandle = -1;
                        foreach (ObjectId acObjId in btr)
                        {
                            if (acObjId.ObjectClass.Name == "AcDbViewport")
                            {
                                Viewport vp = tr.GetObject(acObjId, OpenMode.ForRead) as Viewport;

                                if (lowestHandle < 0)
                                {
                                    lowestHandle = vp.Handle.Value;
                                    paperVp      = vp;
                                }
                                else if (vp.Handle.Value < lowestHandle)
                                {
                                    paperVp      = vp;
                                    lowestHandle = vp.Handle.Value;
                                }
                            }
                        }
                        if (paperVp == null)
                        {
                            return;
                        }
                        paperVp.UpgradeOpen();

                        double scrRatio = (paperVp.Width / paperVp.Height);

                        Matrix3d matWCS2DCS = Matrix3d.PlaneToWorld(paperVp.ViewDirection);

                        matWCS2DCS = Matrix3d.Displacement(paperVp.ViewTarget - Point3d.Origin) * matWCS2DCS;

                        matWCS2DCS = Matrix3d.Rotation(-paperVp.TwistAngle,
                                                       paperVp.ViewDirection,
                                                       paperVp.ViewTarget)
                                     * matWCS2DCS;

                        matWCS2DCS = matWCS2DCS.Inverse();

                        Extents3d extents = GetExtents(db, btr);

                        extents.TransformBy(matWCS2DCS);

                        double width = (extents.MaxPoint.X - extents.MinPoint.X);

                        double height = (extents.MaxPoint.Y - extents.MinPoint.Y);

                        Point2d center = new Point2d((extents.MaxPoint.X + extents.MinPoint.X) * 0.5,
                                                     (extents.MaxPoint.Y + extents.MinPoint.Y) * 0.5);

                        if (width > (height * scrRatio))
                        {
                            height = width / scrRatio;
                        }

                        paperVp.ViewHeight = height;
                        paperVp.ViewCenter = center;

                        //Was Changed
                        objDWG.IsChanged = true;
                    }
                }));
            }

            #endregion
        }
        //Block Insertor
        static public void InsestBlock(BlockModel objBlockModel)
        {
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            //InsertionState
            BlockInsetions insState = BlockInsetions.Insert;

            //Variables
            Point3d p3dInsetion     = new Point3d();
            Point3d p3dMatrixCorner = new Point3d();


            //Get objId
            ObjectId objId = ArCaRefMgrController.GetBlockId(objBlockModel);
            //Create BlockReference
            BlockReference blockRef = new BlockReference(new Point3d(), objId);
            //Get BlockPropertyModel
            BlockPropModel objBloPro = objBlockModel.LstBlockProp[0];

            //Set properties in BlockRefernce
            blockRef.Rotation     = ArCaUtils.DegreeToRadian(objBloPro.Angle);
            blockRef.ScaleFactors = new Scale3d(objBloPro.SclX, objBloPro.SclY, objBloPro.SclZ);

            //Mirror Settings
            bool bTop  = true;
            bool bLeft = true;

            //Strategy for Preview in PointMonitor
            _PointMonitorStrategy = new PointMonitorStrategy(delegate(object sender, PointMonitorEventArgs e)
            {
                try
                {
                    switch (insState)
                    {
                    case BlockInsetions.Insert:
                        blockRef.Position = e.Context.ComputedPoint;
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Rotate:
                        blockRef.Rotation = Vector3d.XAxis.GetAngleTo(p3dInsetion.GetVectorTo(e.Context.ComputedPoint), Vector3d.ZAxis);
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Scale:
                        blockRef.ScaleFactors = new Scale3d(p3dInsetion.DistanceTo(e.Context.ComputedPoint));
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Mirror:

                        if (e.Context.ComputedPoint.X < p3dInsetion.X && bLeft)
                        {
                            blockRef.ScaleFactors = new Scale3d(-(blockRef.ScaleFactors.X), blockRef.ScaleFactors.Y, blockRef.ScaleFactors.Z);
                            bLeft = false;
                        }
                        else if (e.Context.ComputedPoint.X > p3dInsetion.X && !bLeft)
                        {
                            blockRef.ScaleFactors = new Scale3d(-(blockRef.ScaleFactors.X), blockRef.ScaleFactors.Y, blockRef.ScaleFactors.Z);
                            bLeft = true;
                        }
                        if (e.Context.ComputedPoint.Y < p3dInsetion.Y && bTop)
                        {
                            blockRef.ScaleFactors = new Scale3d(blockRef.ScaleFactors.X, -(blockRef.ScaleFactors.Y), blockRef.ScaleFactors.Z);
                            bTop = false;
                        }
                        else if (e.Context.ComputedPoint.Y > p3dInsetion.Y && !bTop)
                        {
                            blockRef.ScaleFactors = new Scale3d(blockRef.ScaleFactors.X, -(blockRef.ScaleFactors.Y), blockRef.ScaleFactors.Z);
                            bTop = true;
                        }
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Matrix:
                        //Get pt array
                        Point3dCollection pt3DColl = Utils.ArCaUtils.GetPtArray(p3dInsetion, e.Context.ComputedPoint, objBloPro.MatrixHeight, objBloPro.MatrixWidth);
                        double iLimitator          = objBloPro.MatrixMaxQuant;
                        foreach (Point3d pt3D in pt3DColl)
                        {
                            //Insert Block
                            blockRef.Position = pt3D;
                            e.Context.DrawContext.Geometry.Draw(blockRef);
                            //Limitator to evoid chash in machine
                            iLimitator--;
                            if (iLimitator < 1)
                            {
                                break;
                            }
                        }
                        break;
                    }
                }
                catch (System.Exception ex)
                {
                }
            });

            //add pointMonitor
            ed.PointMonitor += new PointMonitorEventHandler(PointMonitor);

            //Looping for Insertion in Loop
            do
            {
                //***Insertion point***
                insState = BlockInsetions.Insert;

                PromptPointOptions opcPt = new PromptPointOptions("\nClick on the insertion point: ");
                opcPt.AllowNone = false;
                PromptPointResult ProPtRes = ed.GetPoint(opcPt);

                if (ProPtRes.Status != PromptStatus.OK)
                {
                    //Command Canceled
                    break;
                }

                p3dInsetion     = ProPtRes.Value;
                p3dMatrixCorner = ProPtRes.Value;

                //***ROTATE***
                if (objBloPro.Rotate)
                {
                    insState = BlockInsetions.Rotate;

                    PromptAngleOptions opcAng = new PromptAngleOptions("\nDefine the rotation angle: ");
                    opcAng.AllowNone    = true;
                    opcAng.UseBasePoint = true;
                    opcAng.BasePoint    = p3dInsetion;
                    opcAng.DefaultValue = 0;
                    PromptDoubleResult ProAngRes = ed.GetAngle(opcAng);

                    if (ProAngRes.Status == PromptStatus.Cancel)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }
                }

                //***SCALE***
                if (objBloPro.Scale)
                {
                    insState = BlockInsetions.Scale;

                    PromptDistanceOptions opcScl = new PromptDistanceOptions("\nDefine the scale factor: ");
                    opcScl.AllowNone    = true;
                    opcScl.UseBasePoint = true;
                    opcScl.BasePoint    = p3dInsetion;
                    opcScl.DefaultValue = 1;
                    PromptDoubleResult ProSclRes = ed.GetDistance(opcScl);

                    if (ProSclRes.Status == PromptStatus.Cancel)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }
                }

                //***MIRROR***
                if (objBloPro.Mirror)
                {
                    insState = BlockInsetions.Mirror;

                    PromptPointOptions opcMatCor = new PromptPointOptions("\nClick on the point that define the mirror direction: ");
                    opcMatCor.AllowNone    = false;
                    opcMatCor.UseBasePoint = true;
                    opcMatCor.BasePoint    = p3dInsetion;
                    PromptPointResult ProMatCorRes = ed.GetPoint(opcMatCor);

                    if (ProMatCorRes.Status != PromptStatus.OK)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }
                }

                //***MATRIX***
                if (objBloPro.Matrix)
                {
                    insState = BlockInsetions.Matrix;

                    PromptPointOptions opcMatCor = new PromptPointOptions("\nClick on the corner point of the matrix: ");
                    opcMatCor.AllowNone = false;
                    PromptPointResult ProMatCorRes = ed.GetPoint(opcMatCor);

                    if (ProMatCorRes.Status != PromptStatus.OK)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }

                    p3dMatrixCorner = ProMatCorRes.Value;
                }

                //***Insertion of Block***
                //Get pt array
                Point3dCollection pt3DColl   = Utils.ArCaUtils.GetPtArray(p3dInsetion, p3dMatrixCorner, objBloPro.MatrixHeight, objBloPro.MatrixWidth);
                double            iLimitator = objBloPro.MatrixMaxQuant;
                foreach (Point3d pt3D in pt3DColl)
                {
                    //Set Position
                    blockRef.Position = pt3D;
                    //We need clone the block reference to obtain a block wiht other objectID in each iteration
                    BlockReference blockRefClone = blockRef.Clone() as BlockReference;
                    //Insert Block
                    Utils.ArCaUtils.InserBlock(db, objBloPro.Explode, blockRefClone);
                    //Limitator to evoid chash in machine
                    iLimitator--;
                    if (iLimitator < 1)
                    {
                        break;
                    }
                }
            } while (objBloPro.Loop);

            //remove pointMonitor
            ed.PointMonitor -= new PointMonitorEventHandler(PointMonitor);
        }
        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);
            }
        }
        private void btSelBlo_Click(object sender, RoutedEventArgs e)
        {
            this.Hide();

            Editor   ed  = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            PromptEntityOptions optSel = new PromptEntityOptions("\nSelect a block: ");

            optSel.SetRejectMessage("\nMust be a Block...");
            optSel.AddAllowedClass(typeof(BlockReference), true);
            PromptEntityResult ProSelRes = ed.GetEntity(optSel);

            switch (ProSelRes.Status)
            {
            case PromptStatus.OK:
                //Criate Wblock
                Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
                using (db)
                {
                    using (Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            BlockReference br = (BlockReference)trans.GetObject(ProSelRes.ObjectId, OpenMode.ForRead);
                            objIdColl.Clear();
                            objIdColl.Add(br.ObjectId);
                            BlockTableRecord btr = new BlockTableRecord();
                            if (br.IsDynamicBlock)
                            {
                                btr = (BlockTableRecord)trans.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead);
                            }
                            else
                            {
                                btr = (BlockTableRecord)trans.GetObject(br.BlockTableRecord, OpenMode.ForRead);
                            }


                            //Define LocalDWG
                            _bDbIsInExternalDWG = false;
                            //Define SelectionIsABlock
                            _SelectionIsABlock = true;
                            //Set Thumbnail
                            _objBlockModNew.btmImage = GetBitmap();
                            //Set Selection Text
                            tblObjSelDesc.Text = "Block \"" + btr.Name + "\" selected.";
                            //Set Name
                            _objBlockModNew.Name = btr.Name;
                            //Set Pick Point
                            tbX.Text = btr.Origin.X.ToString();
                            tbY.Text = btr.Origin.Y.ToString();
                            tbZ.Text = btr.Origin.Z.ToString();

                            //Desable fields
                            tbName.IsEnabled = false;
                            tbX.IsEnabled    = false;
                            tbY.IsEnabled    = false;
                            tbZ.IsEnabled    = false;
                            btPick.IsEnabled = false;

                            //Set Properties
                            //Angle
                            _objBlockModNew.LstBlockProp[0].Angle = ArCaUtils.RadianToDegree(br.Rotation);
                            //Scale
                            _objBlockModNew.LstBlockProp[0].SclX = br.ScaleFactors.X;
                            _objBlockModNew.LstBlockProp[0].SclY = br.ScaleFactors.Y;
                            _objBlockModNew.LstBlockProp[0].SclZ = br.ScaleFactors.Z;
                        }
                        catch (System.Exception ex)
                        {
                            trans.Abort();
                        }
                    }
                }

                break;

            case PromptStatus.Cancel:
                //Command Canceled
                break;
            }
            this.Show();
        }