Example #1
0
        /// <summary>
        /// This is Extension Method for the <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c>
        /// class. It gets the localized name of the Model tab.
        /// </summary>
        /// <param name="mng">Target <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c>
        /// instance.</param>
        /// <returns>Returns the name of current space.</returns>
        public static String GetModelTabLocalizedName(this Db.LayoutManager mng)
        {
            Db.Database db = cad.DocumentManager.MdiActiveDocument.Database;
            String      modelTabLocalizedName = String.Empty;

            using (Db.Transaction tr = db.TransactionManager.StartTransaction())
            {
                Db.BlockTable       bt  = tr.GetObject(db.BlockTableId, Db.OpenMode.ForRead) as Db.BlockTable;
                Db.BlockTableRecord btr = tr.GetObject(bt[Db.BlockTableRecord.ModelSpace], Db.OpenMode.ForRead)
                                          as Db.BlockTableRecord;
                modelTabLocalizedName = (tr.GetObject(btr.LayoutId, Db.OpenMode.ForRead) as Db.Layout).LayoutName;
            }
            return(modelTabLocalizedName);
        }
Example #2
0
        /// <summary>
        /// This is Extension Method for the <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c>
        /// class. It gets the name of the current space in the current Database.
        /// </summary>
        /// <param name="mng">Target <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c>
        /// instance.</param>
        /// <returns>Returns the name of current space.</returns>
        public static String GetCurrentSpaceName(this Db.LayoutManager mng)
        {
            SpaceEnum space = GetCurrentSpaceEnum(mng);

            Db.Database db = cad.DocumentManager.MdiActiveDocument.Database;
            String      modelSpaceLocalizedName = String.Empty;

            using (Db.Transaction tr = db.TransactionManager.StartTransaction())
            {
                Db.BlockTable       bt  = tr.GetObject(db.BlockTableId, Db.OpenMode.ForRead) as Db.BlockTable;
                Db.BlockTableRecord btr = tr.GetObject(bt[Db.BlockTableRecord.ModelSpace], Db.OpenMode.ForRead)
                                          as Db.BlockTableRecord;
                modelSpaceLocalizedName = (tr.GetObject(btr.LayoutId, Db.OpenMode.ForRead) as Db.Layout).LayoutName;
            }
            String result = space == SpaceEnum.Viewport ?
                            "Model" as String : mng.CurrentLayout;

            return(result);
        }
        EnableEventsImp()
        {
            Utils.AcadUi.PrintToCmdLine("\nLayout Manager Events Turned On ...\n");

            m_lMgr = AcDb.LayoutManager.Current;

            m_lMgr.AbortLayoutCopied     += new Autodesk.AutoCAD.DatabaseServices.LayoutEventHandler(event_AbortLayoutCopied);
            m_lMgr.AbortLayoutRemoved    += new Autodesk.AutoCAD.DatabaseServices.LayoutEventHandler(event_AbortLayoutRemoved);
            m_lMgr.AbortLayoutRename     += new Autodesk.AutoCAD.DatabaseServices.LayoutRenamedEventHandler(event_AbortLayoutRename);
            m_lMgr.LayoutCopied          += new Autodesk.AutoCAD.DatabaseServices.LayoutCopiedEventHandler(event_LayoutCopied);
            m_lMgr.LayoutCreated         += new Autodesk.AutoCAD.DatabaseServices.LayoutEventHandler(event_LayoutCreated);
            m_lMgr.LayoutRemoved         += new Autodesk.AutoCAD.DatabaseServices.LayoutEventHandler(event_LayoutRemoved);
            m_lMgr.LayoutRenamed         += new Autodesk.AutoCAD.DatabaseServices.LayoutRenamedEventHandler(event_LayoutRenamed);
            m_lMgr.LayoutsReordered      += new EventHandler(event_LayoutsReordered);
            m_lMgr.LayoutSwitched        += new Autodesk.AutoCAD.DatabaseServices.LayoutEventHandler(event_LayoutSwitched);
            m_lMgr.LayoutToBeCopied      += new Autodesk.AutoCAD.DatabaseServices.LayoutEventHandler(event_LayoutToBeCopied);
            m_lMgr.LayoutToBeRemoved     += new Autodesk.AutoCAD.DatabaseServices.LayoutEventHandler(event_LayoutToBeRemoved);
            m_lMgr.LayoutToBeRenamed     += new Autodesk.AutoCAD.DatabaseServices.LayoutRenamedEventHandler(event_LayoutToBeRenamed);
            m_lMgr.PlotStyleTableChanged += new Autodesk.AutoCAD.DatabaseServices.PlotStyleTableChangedEventHandler(event_PlotStyleTableChanged);
        }
Example #4
0
        /// <summary>
        /// This is Extension Method for the <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c>
        /// class. It gets the current space in the current Database.
        /// </summary>
        /// <param name="mng">Target <c>Autodesk.AutoCAD.DatabaseServices.LayoutManager</c>
        /// instance.</param>
        /// <returns>Returns the SpaceEnum value.</returns>
        public static SpaceEnum GetCurrentSpaceEnum(this Db.LayoutManager mng)
        {
            Db.Database db       = cad.DocumentManager.MdiActiveDocument.Database;
            Int16       tilemode = (Int16)cad.GetSystemVariable("TILEMODE");

            if (tilemode == 1)
            {
                return(SpaceEnum.Model);
            }

            Int16 cvport = (Int16)cad.GetSystemVariable("CVPORT");

            if (cvport == 1)
            {
                return(SpaceEnum.Layout);
            }
            else
            {
                return(SpaceEnum.Viewport);
            }
        }
Example #5
0
        public void CreateLayout()
        {
            using (AcadDb.Transaction tr = AcadFuncs.GetActiveDb().TransactionManager.StartTransaction())
            {
                AcadDb.LayoutManager layout_man = AcadDb.LayoutManager.Current;
                AcadDb.ObjectId      layout_id  = layout_man.CreateLayout("My_Layout");
                layout_man.SetCurrentLayoutId(layout_id);

                AcadDb.Layout layout = tr.GetObject(layout_id, AcadDb.OpenMode.ForRead) as AcadDb.Layout;
                if (null == layout)
                {
                    return;
                }

                AcadDb.BlockTableRecord blk_tbl_rcd = tr.GetObject(layout.BlockTableRecordId, AcadDb.OpenMode.ForRead)
                                                      as AcadDb.BlockTableRecord;
                if (null == blk_tbl_rcd)
                {
                    return;
                }

                AcadDb.ObjectIdCollection vp_ids = layout.GetViewports();
                AcadDb.Viewport           vp     = null;

                foreach (AcadDb.ObjectId vp_id in vp_ids)
                {
                    AcadDb.Viewport vp2 = tr.GetObject(vp_id, AcadDb.OpenMode.ForWrite) as AcadDb.Viewport;
                    if (null != vp2 && 2 == vp2.Number)
                    {
                        vp = vp2;
                        break;
                    }
                }

                if (null == vp)
                {
                    vp = new AcadDb.Viewport();
                    blk_tbl_rcd.UpgradeOpen();
                    blk_tbl_rcd.AppendEntity(vp);
                    tr.AddNewlyCreatedDBObject(vp, true);
                    vp.On     = true;
                    vp.GridOn = true;
                }

                vp.ViewCenter = new AcadGeo.Point2d(0.0, 0.0);
                double scale = 0;
                {
                    AcadEd.PromptDoubleOptions prmpt_pnt = new AcadEd.PromptDoubleOptions("Nhập scale:");
                    AcadEd.PromptDoubleResult  prmpt_ret = AcadFuncs.GetEditor().GetDouble(prmpt_pnt);
                    if (AcadEd.PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return;
                    }

                    scale = prmpt_ret.Value;
                }
                vp.CustomScale = scale;
                vp.Locked      = true;

                tr.Commit();
            }
        }
 LayoutManagerEvents()
 {
     m_lMgr = null;
 }