Beispiel #1
0
        public void CreateViewPost()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                ViewportTable       vpt   = (ViewportTable)trans.GetObject(db.ViewportTableId, OpenMode.ForWrite);
                string              vName = "abc";
                ViewportTableRecord vptr1 = new ViewportTableRecord();
                vptr1.LowerLeftCorner  = new Point2d(0, 0);
                vptr1.UpperRightCorner = new Point2d(0.5, 0.5);
                vptr1.Name             = vName;
                ViewportTableRecord vptr2 = new ViewportTableRecord();
                vptr2.LowerLeftCorner  = new Point2d(0.5, 0);
                vptr2.UpperRightCorner = new Point2d(1, 0.5);
                vptr2.Name             = vName;
                ViewportTableRecord vptr3 = new ViewportTableRecord();
                vptr3.LowerLeftCorner  = new Point2d(0, 0.5);
                vptr3.UpperRightCorner = new Point2d(0.5, 1);
                vptr3.Name             = vName;
                ViewportTableRecord vptr4 = new ViewportTableRecord();
                vptr4.LowerLeftCorner  = new Point2d(0.5, 0.5);
                vptr4.UpperRightCorner = new Point2d(1, 1);
                vptr4.Name             = vName;
                vpt.Add(vptr1);
                vpt.Add(vptr2);
                vpt.Add(vptr3);
                vpt.Add(vptr4);
                trans.AddNewlyCreatedDBObject(vptr1, true);
                trans.AddNewlyCreatedDBObject(vptr2, true);
                trans.AddNewlyCreatedDBObject(vptr3, true);
                trans.AddNewlyCreatedDBObject(vptr4, true);
                Document doc = Application.DocumentManager.MdiActiveDocument;
                if (Application.GetSystemVariable("TILEMODE") == (object)1)
                {
                    doc.SendStringToExecute("-VPORTS 4 ", false, false, false);
                }
                else
                {
                    doc.SendStringToExecute("-VPORTS 4 ", false, false, false);
                }
                trans.Commit();
            }
        }
Beispiel #2
0
        // Create a new tiled viewport configuration with two windows
        public void Create_Mode_ViewPort()
        {
            // get the current database
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            using (Transaction acTrans = db.TransactionManager.StartTransaction())
            {
                // open the viewport table for read
                ViewportTable vtab = acTrans.GetObject(db.ViewportTableId, OpenMode.ForRead) as ViewportTable;

                // check to see if the named view 'Test Viewport' exists
                if (vtab.Has("Test_ViewPort") == false)
                {
                    // open the view table for write
                    vtab.UpgradeOpen();

                    // add the new viewport to the viewport table and the transaction
                    ViewportTableRecord vptableRecordLwr = new ViewportTableRecord();
                    vtab.Add(vptableRecordLwr);
                    acTrans.AddNewlyCreatedDBObject(vptableRecordLwr, true);

                    // name the new viewport 'Test_ViewPort' and assign it to be the lower half of the drawing window
                    vptableRecordLwr.Name             = "Test_ViewPort";
                    vptableRecordLwr.LowerLeftCorner  = new Point2d(0, 0);
                    vptableRecordLwr.UpperRightCorner = new Point2d(1, 0.5);

                    // Add the new viewport to the viewport table and the transaction
                    ViewportTableRecord vptableRecordUpr = new ViewportTableRecord();
                    vtab.Add(vptableRecordUpr);
                    acTrans.AddNewlyCreatedDBObject(vptableRecordUpr, true);

                    // name the new viewport 'Test_ViewPort' and assign it to be the upper half of the drawing window
                    vptableRecordUpr.Name             = "Test_ViewPort";
                    vptableRecordUpr.LowerLeftCorner  = new Point2d(0, .5);
                    vptableRecordUpr.UpperRightCorner = new Point2d(1, 1);

                    // to assign the new viewport as the active viewpport,
                    // the viewport named active nedd to be removed and recreated based on "Test_ViewPort"

                    // step through each object in the symbol table
                    foreach (ObjectId acObjectId in vtab)
                    {
                        // open the object for read
                        ViewportTableRecord acVportTblRec = acTrans.GetObject(acObjectId, OpenMode.ForRead) as ViewportTableRecord;

                        // see if it is one of the active viewports, and if so erase it
                        if (acVportTblRec.Name == "*Active")
                        {
                            acVportTblRec.UpgradeOpen();
                            acVportTblRec.Erase();
                        }
                    }
                    // clone the new viewport as the active viewports
                    foreach (ObjectId acObjId in vtab)
                    {
                        // open the object for read
                        ViewportTableRecord acVportTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead) as ViewportTableRecord;

                        // see if it is one of the active viewports, and if so erase it
                        if (acVportTblRec.Name == "*Test_ViewPort")
                        {
                            ViewTableRecord acVportTblRecClone = acVportTblRec.Clone() as ViewTableRecord;
                            // add the new viewport to the viewport table and the transaction
                            vtab.Add(acVportTblRecClone);
                            acVportTblRecClone.Name = "*Active";
                            acTrans.AddNewlyCreatedDBObject(acVportTblRecClone, true);
                        }
                    }
                    // update display with the new tiled viewports arrangment
                    Editor ed = doc.Editor;
                    ed.UpdateTiledViewportsFromDatabase();
                    // commit changes
                    acTrans.Commit();
                }
            }
        }
Beispiel #3
0
        public static void QuickView()
        {
            List <Point2d> viewsLower = new List <Point2d>()
            {
                new Point2d(0, 0.5), new Point2d(0, 0), new Point2d(0.5, 0)
            };
            List <Point2d> viewsUpper = new List <Point2d>()
            {
                new Point2d(0.5, 1), new Point2d(0.5, 0.5), new Point2d(1, 0.5)
            };
            List <OrthographicView> viewsDirection = new List <OrthographicView>()
            {
                OrthographicView.TopView, OrthographicView.FrontView, OrthographicView.RightView,
            };

            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            Editor ed = doc.Editor;

            Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Focus();

            LayoutManager layoutManager = LayoutManager.Current;

            if (layoutManager.LayoutExists("QuickView"))
            {
                layoutManager.CurrentLayout = "Model";
                FirstViewPort = (short)Application.GetSystemVariable("CVPORT");
                Application.SetSystemVariable("CVPORT", FirstViewPort);
                ed.Command("-vports", "toggle");
                return;
            }

            using (DocumentLock lockDoc = doc.LockDocument())
            {
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    ViewportTable       vportTable    = trans.GetObject(db.ViewportTableId, OpenMode.ForWrite) as ViewportTable;
                    ViewportTableRecord vportTableRec = trans.GetObject(ed.ActiveViewportId, OpenMode.ForWrite) as ViewportTableRecord;

                    BlockTable       bTable    = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                    BlockTableRecord bTableRec = trans.GetObject(bTable[BlockTableRecord.PaperSpace], OpenMode.ForWrite) as BlockTableRecord;

                    FirstViewPort = System.Convert.ToInt16(vportTableRec.Number);

                    vportTableRec.LowerLeftCorner  = new Point2d(0.5, 0.5);
                    vportTableRec.UpperRightCorner = new Point2d(1, 1);

                    vportTableRec.ViewDirection = new Vector3d(Math.Sqrt(1.0 / 3.0), -Math.Sqrt(1.0 / 3.0), Math.Sqrt(1.0 / 3.0));

                    DBDictionary dict = trans.GetObject(db.VisualStyleDictionaryId, OpenMode.ForRead) as DBDictionary;

                    vportTableRec.VisualStyleId = dict.GetAt("2DWireframe");

                    for (int i = 0; i < 3; i++)
                    {
                        using (ViewportTableRecord vportTableRecNew = new ViewportTableRecord())
                        {
                            vportTable.Add(vportTableRecNew);

                            trans.AddNewlyCreatedDBObject(vportTableRecNew, true);

                            vportTableRecNew.SetViewDirection(viewsDirection[i]);

                            vportTableRecNew.Name = "*Active";

                            vportTableRecNew.LowerLeftCorner  = viewsLower[i];
                            vportTableRecNew.UpperRightCorner = viewsUpper[i];
                        }
                    }

                    ed.UpdateTiledViewportsFromDatabase();

                    foreach (ObjectId vp in vportTable)
                    {
                        ViewportTableRecord vpTR = trans.GetObject(vp, OpenMode.ForRead) as ViewportTableRecord;

                        if (vpTR.Name == "*Active")
                        {
                            Application.SetSystemVariable("CVPORT", vpTR.Number);

                            ed.Command("_.zoom", "_extents");
                            ed.Command("_.zoom", "_scale", "0.7x");
                        }
                    }

                    ObjectId layoutID = layoutManager.CreateLayout("QuickView");

                    Layout layout = trans.GetObject(layoutID, OpenMode.ForRead) as Layout;

                    if (layout.TabSelected == false)
                    {
                        layoutManager.CurrentLayout = layout.LayoutName;
                    }

                    BlockTableRecord blckTableRec = trans.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite) as BlockTableRecord;

                    int count = 0;

                    foreach (ObjectId id in blckTableRec)
                    {
                        Viewport vp = trans.GetObject(id, OpenMode.ForRead) as Viewport;

                        if (vp != null && count != 0)
                        {
                            vp.UpgradeOpen();

                            vp.Height = layout.PlotPaperSize.X * 0.4;
                            vp.Width  = layout.PlotPaperSize.Y * 0.4;

                            vp.CenterPoint = new Point3d(layout.PlotPaperSize.Y * 0.75, layout.PlotPaperSize.X * 0.75, 0); vp.SetViewDirection(OrthographicView.NonOrthoView);

                            vp.ViewDirection = new Vector3d(Math.Sqrt(1.0 / 3.0), -Math.Sqrt(1.0 / 3.0), Math.Sqrt(1.0 / 3.0));

                            vp.GridOn = false;

                            ed.SwitchToModelSpace();

                            ed.Command("_.zoom", "_scale", "0.7x");

                            ed.SwitchToPaperSpace();
                        }

                        count++;
                    }

                    List <Point3d> centerPoints = new List <Point3d>()
                    {
                        new Point3d(layout.PlotPaperSize.Y * 0.25, layout.PlotPaperSize.X * 0.75, 0), new Point3d(layout.PlotPaperSize.Y * 0.25, layout.PlotPaperSize.X * 0.25, 0), new Point3d(layout.PlotPaperSize.Y * 0.75, layout.PlotPaperSize.X * 0.25, 0)
                    };

                    for (int i = 0; i < 3; i++)
                    {
                        using (Viewport vp = new Viewport())
                        {
                            ed.SwitchToPaperSpace();

                            blckTableRec.AppendEntity(vp);
                            trans.AddNewlyCreatedDBObject(vp, true);

                            vp.CenterPoint = centerPoints[i];

                            vp.Height = layout.PlotPaperSize.X * 0.4;
                            vp.Width  = layout.PlotPaperSize.Y * 0.4;

                            vp.SetViewDirection(viewsDirection[i]);

                            vp.On = true;

                            ed.SwitchToModelSpace();

                            ed.Command("_.zoom", "_extents");

                            ed.Command("_.zoom", "_scale", "0.7x");
                        }
                    }

                    ed.SwitchToPaperSpace();

                    trans.Commit();
                }
            }

            menu.QuickViewButton.Text = "Toggle viewport";
        }