Ejemplo n.º 1
0
        private DBDictionary GetDict(Transaction tr)
        {
            DBDictionary dict    = null;
            DBDictionary db_dict = tr.GetObject(AcadFuncs.GetActiveDb().NamedObjectsDictionaryId, OpenMode.ForRead)
                                   as DBDictionary;

            if (null == db_dict)
            {
                tr.Dispose();
                return(null);
            }

            if (!db_dict.Contains(DICT_NAME))
            {
                dict = new DBDictionary();
                dict.TreatElementsAsHard = true;
                db_dict.UpgradeOpen();
                db_dict.SetAt(DICT_NAME, dict);
                tr.AddNewlyCreatedDBObject(dict, true);
                db_dict.DowngradeOpen();
            }
            else
            {
                dict = tr.GetObject((ObjectId)db_dict[DICT_NAME], OpenMode.ForRead) as DBDictionary;
            }

            return(dict);
        }
Ejemplo n.º 2
0
        public void HighlightSoftPointer()
        {
            using (Transaction tr = AcadFuncs.GetActiveDb().TransactionManager.StartTransaction())
            {
                DBDictionary dict = GetDict(tr);
                if (null == dict)
                {
                    return;
                }

                Xrecord xrec = tr.GetObject(dict.GetAt(XREC_NAME), OpenMode.ForRead) as Xrecord;
                if (null == xrec)
                {
                    return;
                }

                ObjectId obj_id = (ObjectId)xrec.Data.AsArray()[0].Value;

                Entity ent = tr.GetObject(obj_id, OpenMode.ForRead) as Entity;
                if (null == ent)
                {
                    return;
                }

                if (ent is Line)
                {
                    Line line = ent as Line;
                    line.UpgradeOpen();
                    line.ColorIndex = 1;
                }

                tr.Commit();
            }
        }
Ejemplo n.º 3
0
        private ObjectId GetBlkTblRcd(Transaction tr)
        {
            BlockTable       blk_tbl = AcadFuncs.GetBlkTbl(tr);
            BlockTableRecord blk_ref = new BlockTableRecord();

            blk_ref.Name = "TestBlkRef";
            blk_tbl.UpgradeOpen();
            blk_tbl.Add(blk_ref);
            tr.AddNewlyCreatedDBObject(blk_ref, true);
            return(blk_ref.Id);
        }
Ejemplo n.º 4
0
        public void DrawLine2()
        {
            try
            {
                AcadFuncs.AddNewEnt(new Line(new AcadGeo.Point3d(0.0, 0.0, 0.0), new AcadGeo.Point3d(1.0, 1.0, 0.0)));

                AcadFuncs.AddNewEnt(new Line(new AcadGeo.Point3d(1.0, 1.0, 0.0), new AcadGeo.Point3d(1.0, 0.0, 0.0)));
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 5
0
        public void SoftPointer()
        {
            using (Transaction tr = AcadFuncs.GetActiveDb().TransactionManager.StartTransaction())
            {
                DBDictionary dict = GetDict(tr);
                if (null == dict)
                {
                    return;
                }

                ObjectId sel_ent_id = GetBlkTblRcd(tr);                 // PickSingleEnt();
                if (ObjectId.Null == sel_ent_id)
                {
                    return;
                }

                AddXRecord(tr, dict, XREC_NAME, sel_ent_id);
                tr.Commit();
            }
        }
Ejemplo n.º 6
0
        private ObjectId PickSingleEnt()
        {
            using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
                {
                    PromptEntityResult prmpt_ret = AcadFuncs.GetEditor().GetEntity("Chọn một đối tượng line");
                    if (PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return(ObjectId.Null);
                    }

                    ObjectId obj_id = prmpt_ret.ObjectId;
                    tr.Commit();

                    return(obj_id);
                }
            }
        }
Ejemplo n.º 7
0
        public void AddXdata()
        {
            using (Transaction tr = AcadFuncs.GetActiveDb().TransactionManager.StartTransaction())
            {
                RegAppTable reg_app = tr.GetObject(AcadFuncs.GetActiveDb().RegAppTableId, OpenMode.ForRead) as RegAppTable;
                if (null == reg_app)
                {
                    tr.Dispose();
                    return;
                }

                if (!reg_app.Has(XDATA_APP))
                {
                    RegAppTableRecord reg_app_rcd = new RegAppTableRecord();
                    reg_app_rcd.Name = XDATA_APP;

                    reg_app.UpgradeOpen();
                    reg_app.Add(reg_app_rcd);
                    tr.AddNewlyCreatedDBObject(reg_app_rcd, true);
                }

                PromptEntityResult prmpt_ent_ret = AcadFuncs.GetEditor().GetEntity("Chọn 1 entity:");
                Entity             ent           = tr.GetObject(prmpt_ent_ret.ObjectId, OpenMode.ForRead) as Entity;
                if (null == ent)
                {
                    tr.Dispose();
                    return;
                }

                ent.UpgradeOpen();
                ResultBuffer buffer = new ResultBuffer();
                buffer.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, XDATA_APP));
                buffer.Add(new TypedValue((int)DxfCode.ExtendedDataReal, 100.0));
                ent.XData = buffer;

                tr.Commit();
            }
        }
Ejemplo n.º 8
0
        public void DrawLine2()
        {
            AcadFuncs.AddNewEnt(new Line(new AcadGeo.Point3d(0.0, 0.0, 0.0), new AcadGeo.Point3d(1.0, 1.0, 0.0)));

            AcadFuncs.AddNewEnt(new Line(new AcadGeo.Point3d(1.0, 1.0, 0.0), new AcadGeo.Point3d(1.0, 0.0, 0.0)));
        }