Example #1
0
        //open -> opened -> modified -> (1) tr.Dispose() -> closed   -> (2) closed    (

        public void ClosedHandler(object sender, AcadDb.ObjectClosedEventArgs args)
        {
            using (var tr = AcadFuncs.GetActiveDb().TransactionManager.StartOpenCloseTransaction())
            {
                AcadDb.BlockTableRecord model_space = AcadFuncs.GetModelSpace(tr);
                model_space.UpgradeOpen();

                AcadDb.DBText text = new AcadDb.DBText();
                text.Position   = curr_pl.StartPoint;
                text.TextString = curr_pl.Length.ToString();

                model_space.AppendEntity(text);
                tr.AddNewlyCreatedDBObject(text, true);
                tr.Commit();
            }
        }
Example #2
0
        static public void AddNewEnt(AcadDB.Entity ent)
        {
            AcadDB.Database db = GetActiveDB();

            using (AcadDB.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcadDB.BlockTableRecord model_space = GetModelSpace(tr);
                if (null == model_space)
                {
                    return;
                }

                model_space.UpgradeOpen();
                model_space.AppendEntity(ent);

                tr.AddNewlyCreatedDBObject(ent, true);

                tr.Commit();
            }
        }
Example #3
0
        public void CreateNotification()
        {
            using (AcadDb.Transaction tr = AcadFuncs.GetActiveDb().TransactionManager.StartTransaction())
            {
                AcadDb.Polyline pl = new AcadDb.Polyline();
                pl.AddVertexAt(0, new AcadGeo.Point2d(0.0, 0.0), 0.0, 0.0, 0.0);
                pl.AddVertexAt(1, new AcadGeo.Point2d(10.0, 0.0), 0.0, 0.0, 0.0);

                AcadDb.BlockTableRecord model_space = AcadFuncs.GetModelSpace(tr);

                model_space.UpgradeOpen();
                model_space.AppendEntity(pl);
                tr.AddNewlyCreatedDBObject(pl, true);

                pl.ObjectClosed += new AcadDb.ObjectClosedEventHandler(ClosedHandler);
                //pl.Modified += new EventHandler(ModifiedHandler);
                curr_pl = pl;

                tr.Commit();
            }
        }
Example #4
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();
            }
        }