Ejemplo n.º 1
0
        private static void AddRegAppTableRecord(string applicationName)
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            using (doc.LockDocument())
            {
                using (Transaction tr = DatabaseUtil.GetTransaction(db))
                {
                    RegAppTable rat = tr.GetObject(db.RegAppTableId, OpenMode.ForRead, false) as RegAppTable;

                    if (!rat.Has(applicationName))
                    {
                        rat.UpgradeOpen();
                        RegAppTableRecord ratr = new RegAppTableRecord();
                        ratr.Name = applicationName;
                        rat.Add(ratr);
                        tr.AddNewlyCreatedDBObject(ratr, true);
                    }

                    tr.Commit();
                }
            }
        }
Ejemplo n.º 2
0
        public Poze()
        {
            InitializeComponent();
            imagini      = new SortedDictionary <int, string>();
            imaginiCheie = new SortedDictionary <int, string>();
            listaFisiere = new List <string>();

            ObjectIdCollection idAxuri = civDoc.GetAlignmentIds();

            db = acadDoc.Database;
            ed = acadDoc.Editor;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId idAx in idAxuri)
                {
                    Axuri.Add((Alignment)trans.GetObject(idAx, OpenMode.ForRead));
                    comboBoxAx.Items.Add(Axuri.Last());
                }
                RegAppTable rat = (RegAppTable)trans.GetObject(db.RegAppTableId, OpenMode.ForWrite, false);
                if (!rat.Has("OVIDIU"))
                {
                    //rat.UpgradeOpen();
                    RegAppTableRecord ratr = new RegAppTableRecord();
                    ratr.Name = "OVIDIU";
                    rat.Add(ratr);
                    trans.AddNewlyCreatedDBObject(ratr, true);
                }
                trans.Commit();
            }
            comboBoxAx.SelectedIndex = 0;


            //SelectieDirector();
            //AfisarePoze();
        }
Ejemplo n.º 3
0
Archivo: xData.cs Proyecto: 15831944/EM
        AddRegAppTableRecord(string nameApp)
        {
            Database DB = BaseObjs._db;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    RegAppTable RAT = (RegAppTable)tr.GetObject(DB.RegAppTableId, OpenMode.ForRead);
                    if (!RAT.Has(nameApp))
                    {
                        RAT.UpgradeOpen();
                        RegAppTableRecord RAtr = new RegAppTableRecord();
                        RAtr.Name = nameApp;
                        RAT.Add(RAtr);
                        tr.AddNewlyCreatedDBObject(RAtr, true);
                    }
                    tr.Commit();
                }//end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " xData.cs: line: 711");
            }
        }
Ejemplo n.º 4
0
        public static void AddRegAppTableRecord(string regAppName)
        {
            Document doc =
                Application.DocumentManager.MdiActiveDocument;
            Editor   ed = doc.Editor;
            Database db = doc.Database;

            Transaction tr =
                doc.TransactionManager.StartTransaction();

            using (tr)
            {
                RegAppTable rat =
                    (RegAppTable)tr.GetObject(
                        db.RegAppTableId,
                        OpenMode.ForRead,
                        false
                        );
                if (!rat.Has(regAppName))
                {
                    rat.UpgradeOpen();
                    RegAppTableRecord ratr =
                        new RegAppTableRecord();
                    ratr.Name = regAppName;
                    rat.Add(ratr);
                    tr.AddNewlyCreatedDBObject(ratr, true);
                }
                tr.Commit();
            }
        }
Ejemplo n.º 5
0
        public static void RegisterApp(string appName)//注册应用程序名称
        {
            DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.

                                   DocumentManager.MdiActiveDocument.LockDocument();

            using (Transaction trans = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
            {
                Database workingdatabase = HostApplicationServices.WorkingDatabase;

                RegAppTable appTbl = trans.GetObject(workingdatabase.RegAppTableId, OpenMode.ForWrite) as RegAppTable;

                if (!appTbl.Has(appName))
                {
                    RegAppTableRecord appTblRcd = new RegAppTableRecord();
                    appTblRcd.Name = appName;
                    appTbl.Add(appTblRcd);

                    trans.AddNewlyCreatedDBObject(appTblRcd, true);
                }

                trans.Commit();
            }

            docLock.Dispose();
        }
        public static bool AddRegAppId()
        {
            Document acDoc    = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database acCurrDb = acDoc.Database;
            Editor   acEditor = acDoc.Editor;

            using (Transaction acTrans = acCurrDb.TransactionManager.StartTransaction())
            {
                try
                {
                    RegAppTable acRegAppTbl = acTrans.GetObject(acCurrDb.RegAppTableId, OpenMode.ForRead) as RegAppTable;
                    if (!acRegAppTbl.Has(JPP_App_Config_Params.JPP_APP_NAME))
                    {
                        using (RegAppTableRecord acRegAppTblRec = new RegAppTableRecord())
                        {
                            acRegAppTblRec.Name = JPP_App_Config_Params.JPP_APP_NAME;
                            acRegAppTbl.UpgradeOpen();
                            acRegAppTbl.Add(acRegAppTblRec);
                            acTrans.AddNewlyCreatedDBObject(acRegAppTblRec, true);
                        }
                        acTrans.Commit();
                    }
                    return(true);
                }
                catch (Autodesk.AutoCAD.Runtime.Exception acException)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog
                        ("The following exception was caught: \n" + acException.Message
                        + "\nError registering JPP App!");
                    acTrans.Commit();
                    return(false);
                }
            }
        }
Ejemplo n.º 7
0
        public static void AddRegAppTableRecord()
        {
            try
            {
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                Editor   ed  = doc.Editor;

                Database db = doc.Database;

                using (var Lock = doc.LockDocument())
                {
                    using (Transaction tr = doc.TransactionManager.StartTransaction())
                    {
                        RegAppTable rat = (RegAppTable)tr.GetObject(db.RegAppTableId, OpenMode.ForRead, false);

                        if (!rat.Has("JPP"))
                        {
                            rat.UpgradeOpen();
                            RegAppTableRecord ratr = new RegAppTableRecord();
                            ratr.Name = "JPP";
                            rat.Add(ratr);
                            tr.AddNewlyCreatedDBObject(ratr, true);
                        }
                        tr.Commit();
                    }
                }
            } catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                Logger.Log("Error in registering AppTableRecord - " + e.Message + "\n");
            }
            catch (System.Exception e)
            {
                Logger.Log("Error in registering AppTableRecord - " + e.Message + "\n");
            }
        }
Ejemplo n.º 8
0
        public void SaveToEntity(Entity ent)
        {
            // Make sure application name is registered
            // If we were to save the ResultBuffer to an Xrecord.Data,
            // then we would not need to have a registered application name

            Transaction tr =
                ent.Database.TransactionManager.TopTransaction;

            RegAppTable regTable =
                (RegAppTable)tr.GetObject(
                    ent.Database.RegAppTableId, OpenMode.ForWrite);

            if (!regTable.Has(ApplicationName))
            {
                RegAppTableRecord app = new RegAppTableRecord();
                app.Name = ApplicationName;
                regTable.Add(app);
                tr.AddNewlyCreatedDBObject(app, true);
            }

            using (ResultBuffer resBuf = SaveToResBuf())
            {
                ent.XData = resBuf;
            }
        }
Ejemplo n.º 9
0
            public void Create(AC_Line line)
            {
                if (line.XData == null)
                {
                    if (askForDistances(line))
                    {
                        tr.start_Transaction();
                        RegAppTable rat = (RegAppTable)tr.AC_Tr.GetObject(tr.AC_Db.RegAppTableId, OpenMode.ForRead, false);
                        if (!rat.Has("TRIANGULATE"))
                        {
                            rat.UpgradeOpen();
                            RegAppTableRecord ratr = new RegAppTableRecord();
                            ratr.Name = "TRIANGULATE";
                            rat.Add(ratr);
                            tr.AC_Tr.AddNewlyCreatedDBObject(ratr, true);
                        }
                        tr.AC_Tr.Commit();
                        tr.AC_Tr.Dispose();

                        ResultBuffer rb = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "TRIANGULATE"), new TypedValue((int)DxfCode.ExtendedDataAsciiString, radius[0].ToString()), new TypedValue((int)DxfCode.ExtendedDataAsciiString, radius[1].ToString()), new TypedValue((int)DxfCode.ExtendedDataAsciiString, Guid.NewGuid().ToString()));
                        line.XData = rb;

                        Triangulations triang = new Triangulations();
                        triang.Show(line);
                    }
                }
                else
                {
                    tr.AC_Doc.Editor.WriteMessage("This line is alredy triangulated \n");
                }
            }
Ejemplo n.º 10
0
        /// <summary>
        /// Sets the X data.
        /// </summary>
        /// <param name="transaction">The transaction.</param>
        /// <param name="objectId">The object id.</param>
        /// <param name="applicationName">Name of the application.</param>
        /// <param name="xData">The x data.</param>
        public static void SetXData(Transaction transaction, ObjectId objectId, string applicationName, ResultBuffer xData)
        {
            //_logger.Debug("Start SetXData");
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }
            if (transaction.IsDisposed)
            {
                throw new ArgumentException("transaction is disposed", "transaction");
            }

            RegAppTable rat = transaction.GetObject(objectId.Database.RegAppTableId, OpenMode.ForWrite) as RegAppTable;

            if (!rat.Has(applicationName))
            {
                RegAppTableRecord raRec = new RegAppTableRecord();
                raRec.Name = applicationName;
                rat.Add(raRec);
                transaction.AddNewlyCreatedDBObject(raRec, true);
            }

            Entity entity = transaction.GetObject(objectId, OpenMode.ForWrite) as Entity;

            entity.XData = xData;
            //_logger.Debug("End SetXData");
        }
Ejemplo n.º 11
0
        private void btn_change_pline3D_stack_xdata_Click(object sender, EventArgs e)
        {
            double stack = Convert.ToDouble(tbx_pline3d_xdata_stack.Text.Trim());
            Editor ed    = cadSer.Application.DocumentManager.MdiActiveDocument.Editor;


            Database db     = HostApplicationServices.WorkingDatabase;
            var      middoc = cadSer.Application.DocumentManager.MdiActiveDocument;


            string appname = "zjy_1_1_1";


            ObjectId plineID  = ed.GetEntity(new PromptEntityOptions("\n选取HDM辅助线!!!")).ObjectId;
            var      doc_lock = middoc.LockDocument();

            DBObject dbo;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                dbo = trans.GetObject(plineID, OpenMode.ForWrite);

                while (!dbo.GetType().Equals(typeof(Polyline3d)))
                {
                    ed.WriteMessage("\n刚才选取的不是HDM辅助线,请重新选择!!!");
                    plineID = ed.GetEntity(new PromptEntityOptions("\n选取HDM辅助线!!!")).ObjectId;
                    dbo     = trans.GetObject(plineID, OpenMode.ForWrite);
                }

                Polyline3d pline3d_modify = (Polyline3d)dbo;
                if (pline3d_modify.XData.AsArray().Length > 0)
                {
                    ed.WriteMessage("\n桩号为:" + pline3d_modify.XData.AsArray()[1].Value.ToString() + "\n");
                }
                SortedDictionary <double, Polyline3d> hdm_pline3d_dic = new SortedDictionary <double, Polyline3d>();

                RegAppTable apptb1 = trans.GetObject(db.RegAppTableId, OpenMode.ForWrite) as RegAppTable;
                if (!apptb1.Has(appname))
                {
                    RegAppTableRecord app = new RegAppTableRecord();
                    app.Name = appname;
                    apptb1.Add(app);
                    trans.AddNewlyCreatedDBObject(app, true);
                }



                ResultBuffer resultBuffer = new ResultBuffer();

                resultBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, appname));
                resultBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, stack));

                pline3d_modify.XData = resultBuffer;

                zjyCAD.ToModelSpace(pline3d_modify, db);

                trans.Commit();
            }
        }
Ejemplo n.º 12
0
        //用户添加扩展记录
        public static void UserAddXData()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("添加扩充数据 XDATA\n");
            PromptEntityOptions entOps = new PromptEntityOptions("选择实体对象");
            PromptEntityResult  entRes;

            entRes = ed.GetEntity(entOps);
            if (entRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("选择对象失败,退出");
                return;
            }
            //出现添加扩展数据面板
            AddEntityXDataForm addentityxdataform = new AddEntityXDataForm();

            addentityxdataform.Show();

            ObjectId objId = entRes.ObjectId;
            Database db    = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                RegAppTable appTbl     = trans.GetObject(db.RegAppTableId, OpenMode.ForWrite) as RegAppTable;
                string      DateStr    = DateTime.Now.ToString("yyyyMMddHHmmssms"); //日期
                Random      rd         = new Random();                              //用于生成随机数
                string      AppNamestr = DateStr + rd.Next(10, 99);                 //带日期的随机数
                Entity      ent        = trans.GetObject(objId, OpenMode.ForWrite) as Entity;

                if (!appTbl.Has(AppNamestr))
                {
                    RegAppTableRecord appTblRcd = new RegAppTableRecord();
                    appTblRcd.Name = AppNamestr;
                    appTbl.Add(appTblRcd);
                    trans.AddNewlyCreatedDBObject(appTblRcd, true);
                }

                ResultBuffer resBuf = new ResultBuffer(
                    new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNamestr),
                    new TypedValue((int)DxfCode.ExtendedDataLayerName, "0"),
                    new TypedValue((int)DxfCode.ExtendedDataReal, 1.23479137438413E+40),
                    new TypedValue((int)DxfCode.ExtendedDataInteger16, 32767),
                    new TypedValue((int)DxfCode.ExtendedDataInteger32, 32767),
                    new TypedValue((int)DxfCode.ExtendedDataScale, 10),
                    new TypedValue((int)DxfCode.ExtendedDataWorldXCoordinate, new Point3d(10, 10, 0)));
                resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "这是追加的数据"));
                resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "我又一次追加了数据"));
                resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 32767));

                if (ent.XData != null)
                {
                    ed.WriteMessage("该对象已有扩展记录,不需要再次添加,只需在原有记录进行修改");
                    return;
                }
                ent.XData = resBuf;
                trans.Commit();
            }
        }
Ejemplo n.º 13
0
        public static void LArrow()
        {
            Document            doc       = Application.DocumentManager.MdiActiveDocument;
            Editor              ed        = doc.Editor;
            PromptDoubleOptions optDouble = new PromptDoubleOptions("\n请输入箭头长度:");

            optDouble.AllowNone       = true;
            optDouble.AllowZero       = false;
            optDouble.DefaultValue    = ArrowLength;
            optDouble.UseDefaultValue = true;

            PromptDoubleResult resDouble = ed.GetDouble(optDouble);

            if (resDouble.Status == PromptStatus.OK)
            {
                //改变箭头长度设定值
                ArrowLength = resDouble.Value;
                PromptPointResult resStartPoint = ed.GetPoint("\n请输入起点:");
                if (resStartPoint.Status == PromptStatus.OK)
                {
                    PromptPointOptions optEndPoint = new PromptPointOptions("\n请输入终点:");
                    optEndPoint.BasePoint    = resStartPoint.Value;
                    optEndPoint.UseBasePoint = true;
                    PromptPointResult resEndPoint = ed.GetPoint(optEndPoint);
                    if (resEndPoint.Status == PromptStatus.OK)
                    {
                        Database db = doc.Database;
                        using (Transaction tr = db.TransactionManager.StartTransaction())
                        {
                            BlockTableRecord btr =
                                (BlockTableRecord)tr.GetObject(
                                    db.CurrentSpaceId,
                                    OpenMode.ForWrite,
                                    false);

                            Line line = new Line(resStartPoint.Value, resEndPoint.Value);
                            btr.AppendEntity(line);
                            tr.AddNewlyCreatedDBObject(line, true);
                            RegAppTable rat =
                                (RegAppTable)tr.GetObject(
                                    db.RegAppTableId,
                                    OpenMode.ForRead,
                                    false);
                            if (!rat.Has(RegAppName))
                            {
                                rat.UpgradeOpen();
                                RegAppTableRecord regapp = new RegAppTableRecord();
                                regapp.Name = RegAppName;
                                rat.Add(regapp);
                                tr.AddNewlyCreatedDBObject(regapp, true);
                            }
                            //附着当前设定的箭头长度
                            SetTo(line);
                            tr.Commit();
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public static void AddRegAppTableRecord(string regAppName, Transaction tr)
        {
            RegAppTable rat = (RegAppTable)tr.GetObject(Command.Database.RegAppTableId, OpenMode.ForRead, false);

            if (!rat.Has(regAppName))
            {
                rat.UpgradeOpen();
                RegAppTableRecord ratr = new RegAppTableRecord();
                ratr.Name = regAppName;
                rat.Add(ratr);
                tr.AddNewlyCreatedDBObject(ratr, true);
            }
        }
Ejemplo n.º 15
0
        public static void AddRegAppTableRecord(Database db, Transaction tr, string name)
        {
            RegAppTable rat = (RegAppTable)tr.GetObject(db.RegAppTableId, OpenMode.ForRead);

            if (!rat.Has(ConstantName.tableAlias))
            {
                rat.UpgradeOpen();
                RegAppTableRecord ratr = new RegAppTableRecord();
                ratr.Name = ConstantName.tableAlias;
                rat.Add(ratr);
                tr.AddNewlyCreatedDBObject(ratr, true);
            }
        }
Ejemplo n.º 16
0
        private void AddTableRecord(string data, Database db, Transaction tr, Table t)
        {
            string      regName = uriInit;
            RegAppTable rat     = (RegAppTable)tr.GetObject(db.RegAppTableId, OpenMode.ForRead);

            if (!rat.Has(regName))
            {
                rat.UpgradeOpen();
                RegAppTableRecord ratr = new RegAppTableRecord();
                ratr.Name = regName;
                rat.Add(ratr);
                tr.AddNewlyCreatedDBObject(ratr, true);
            }
        }
Ejemplo n.º 17
0
 public static void RegAppIsoline(Database db)
 {
     using (RegAppTable rat = db.RegAppTableId.Open(OpenMode.ForRead, false) as RegAppTable)
     {
         if (!rat.Has(RegAppNAME))
         {
             rat.UpgradeOpen();
             using (RegAppTableRecord ratr = new RegAppTableRecord())
             {
                 ratr.Name = RegAppNAME;
                 rat.Add(ratr);
             }
         }
     }
 }
Ejemplo n.º 18
0
 bool newRegApp(Database db, string regAppName)
 {
     using (RegAppTable pRegAppTable = (RegAppTable)db.RegAppTableId.GetObject(Teigha.DatabaseServices.OpenMode.ForWrite))
     {
         if (!pRegAppTable.Has(regAppName))
         {
             using (RegAppTableRecord pRegApp = new RegAppTableRecord())
             {
                 pRegApp.Name = regAppName;
                 pRegAppTable.Add(pRegApp);
             }
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Регистрация приложения для записи расширенных данных есл еще не рарегестрировано
        /// </summary>
        /// <param name="db"></param>
        /// <param name="tr"></param>
        public static void RegisterApp(Database db, Transaction tr)
        {
            //Таблица приложений
            RegAppTable regTable = (RegAppTable)tr.GetObject(db.RegAppTableId, OpenMode.ForRead);

            //Создать имя приложения в таблице если еще нет
            if (!regTable.Has(Constants.AppName))
            {
                regTable.UpgradeOpen();

                RegAppTableRecord app = new RegAppTableRecord();
                app.Name = Constants.AppName;
                regTable.Add(app);
                tr.AddNewlyCreatedDBObject(app, true);
            }
        }
Ejemplo n.º 20
0
 public static void AddRegAppTableRecord(Database db, string regAppName)
 {
     using (Transaction tr = db.TransactionManager.StartTransaction())
     {
         RegAppTable rat = (RegAppTable)tr.GetObject(db.RegAppTableId, OpenMode.ForRead, false);
         if (!rat.Has(regAppName))
         {
             rat.UpgradeOpen();
             RegAppTableRecord ratr = new RegAppTableRecord();
             ratr.Name = regAppName;
             rat.Add(ratr);
             tr.AddNewlyCreatedDBObject(ratr, true);
         }
         tr.Commit();
     }
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 确认AppName已注册
 /// </summary>
 /// <param name="db"></param>
 /// <param name="appName"></param>
 public static void AffirmRegApp(Database db, string appName)
 {
     using (Transaction transaction = db.TransactionManager.StartTransaction())
     {
         RegAppTable table = transaction.GetObject(db.RegAppTableId, OpenMode.ForRead) as RegAppTable;
         if (!table.Has(appName))
         {
             table.UpgradeOpen();
             RegAppTableRecord record = new RegAppTableRecord();
             record.Name = appName;
             table.Add(record);
             transaction.AddNewlyCreatedDBObject(record, true);
         }
         transaction.Commit();
     }
 }
Ejemplo n.º 22
0
        public void TestAddEntityXdata()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("添加扩展数据XDATA\n");
            PromptSelectionOptions pso = new PromptSelectionOptions();

            pso.MessageForAdding = "请选择实体集\n";
            PromptSelectionResult psr = ed.GetSelection(pso);

            if (psr.Status != PromptStatus.OK)
            {
                ed.WriteMessage("选择对象失败,退出");
                return;
            }
            SelectionSet ss    = psr.Value;
            int          count = ss.Count;

            ed.WriteMessage("选择了{0}个实体", count);

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                RegAppTable appTable = trans.GetObject(db.RegAppTableId, OpenMode.ForWrite) as RegAppTable;
                if (!appTable.Has("psw"))
                {
                    RegAppTableRecord appTableRec = new RegAppTableRecord();
                    appTableRec.Name = "psw";
                    appTable.Add(appTableRec);
                    trans.AddNewlyCreatedDBObject(appTableRec, true);
                }
                foreach (ObjectId id in ss.GetObjectIds())
                {
                    using (Entity ent = trans.GetObject(id, OpenMode.ForWrite) as Entity)
                    {
                        ent.ColorIndex = 1;
                        ResultBuffer rBuffer = new ResultBuffer(
                            new TypedValue((int)DxfCode.ExtendedDataRegAppName, "psw"),
                            new TypedValue((int)DxfCode.ExtendedDataReal, 20.00)
                            );
                        ent.XData = rBuffer;
                    }
                }
                trans.Commit();
            }
        }
Ejemplo n.º 23
0
        } // form 结束

        /// <summary>
        /// 对实体进行写属性
        /// </summary>
        /// <param name="objId">实体id</param>
        /// <param name="appName">外部数据名</param>
        /// <param name="proStr">属性</param>
        /// <returns>true: 成功 false: 失败</returns>
        public bool AddXdata(ObjectId objId, string appName, string proStr)
        {
            bool retureValue = false;

            try
            {
                using (Database db = HostApplicationServices.WorkingDatabase)
                {
                    using (Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        RegAppTable rAt = (RegAppTable)trans.GetObject(db.RegAppTableId, OpenMode.ForWrite);

                        RegAppTableRecord rAtr;
                        ObjectId          rAtrId = ObjectId.Null;

                        TypedValue tvName = new TypedValue
                                                (DxfCode.ExtendedDataRegAppName.GetHashCode(), appName);
                        TypedValue tvPro = new TypedValue
                                               (DxfCode.ExtendedDataAsciiString.GetHashCode(), proStr);

                        ResultBuffer rb = new ResultBuffer(tvName, tvPro);
                        if (rAt.Has(appName))
                        {
                            rAtrId = rAt[appName];
                        }
                        else
                        {
                            rAtr      = new RegAppTableRecord();
                            rAtr.Name = appName;
                            rAtrId    = rAt.Add(rAtr);
                            trans.AddNewlyCreatedDBObject(rAtr, true);
                        }

                        Entity en = (Entity)trans.GetObject(objId, OpenMode.ForWrite);
                        en.XData = rb;
                        trans.Commit();
                        retureValue = true;
                    }
                }
            }
            catch
            {
                retureValue = false;
            }
            return(retureValue);
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Добавление регистрации приложения в соответсвующую таблицу чертежа
 /// </summary>
 public static void AddRegAppTableRecord(string appName)
 {
     using (var tr = AcadHelpers.Document.TransactionManager.StartTransaction())
     {
         RegAppTable rat = (RegAppTable)tr.GetObject(AcadHelpers.Database.RegAppTableId, OpenMode.ForRead, false);
         if (!rat.Has(appName))
         {
             rat.UpgradeOpen();
             RegAppTableRecord ratr = new RegAppTableRecord
             {
                 Name = appName
             };
             rat.Add(ratr);
             tr.AddNewlyCreatedDBObject(ratr, true);
         }
         tr.Commit();
     }
 }
Ejemplo n.º 25
0
        public static void LArrow()
        {
            Document          doc  = Application.DocumentManager.MdiActiveDocument;
            Editor            ed   = doc.Editor;
            PromptPointResult res1 = ed.GetPoint("\n请输入起点:");

            if (res1.Status == PromptStatus.OK)
            {
                PromptPointOptions opts = new PromptPointOptions("\n请输入终点:");
                opts.BasePoint    = res1.Value;
                opts.UseBasePoint = true;
                PromptPointResult res2 = ed.GetPoint(opts);
                if (res2.Status == PromptStatus.OK)
                {
                    Database db = doc.Database;
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        BlockTableRecord btr =
                            (BlockTableRecord)tr.GetObject(
                                db.CurrentSpaceId,
                                OpenMode.ForWrite,
                                false);
                        Line line = new Line(res1.Value, res2.Value);
                        btr.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);
                        RegAppTable rat =
                            (RegAppTable)tr.GetObject(
                                db.RegAppTableId,
                                OpenMode.ForRead,
                                false);
                        if (!rat.Has(RegAppName))
                        {
                            rat.UpgradeOpen();
                            RegAppTableRecord regapp = new RegAppTableRecord();
                            regapp.Name = RegAppName;
                            rat.Add(regapp);
                            tr.AddNewlyCreatedDBObject(regapp, true);
                        }
                        SetTo(line);
                        tr.Commit();
                    }
                }
            }
        }
Ejemplo n.º 26
0
        public void AddXData()
        {
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //下面的操作用来选择实体以添加扩展数据
                PromptEntityOptions opt = new PromptEntityOptions("请选择实体来添加扩展数据");
                PromptEntityResult  res = ed.GetEntity(opt);
                if (res.Status != PromptStatus.OK)
                {
                    return;
                }
                Circle circ = (Circle)trans.GetObject(res.ObjectId, OpenMode.ForWrite);
                //获取当前数据库的注册应用程序表
                RegAppTable reg = (RegAppTable)trans.GetObject(db.RegAppTableId, OpenMode.ForWrite);
                //如果没有名为"实体扩展数据"的注册应用程序表记录,则
                if (!reg.Has("实体扩展数据"))
                {
                    //创建一个注册应用程序表记录用来表示扩展数据
                    RegAppTableRecord app = new RegAppTableRecord();
                    //设置扩展数据的名字
                    app.Name = "实体扩展数据";
                    //在注册应用程序表加入扩展数据
                    reg.Add(app);
                    trans.AddNewlyCreatedDBObject(app, true);
                }
                //设置扩展数据的内容
                ResultBuffer rb = new ResultBuffer(
                    new TypedValue((int)DxfCode.ExtendedDataRegAppName, "实体扩展数据"),
                    new TypedValue((int)DxfCode.ExtendedDataAsciiString, "字符串扩展数据"),
                    new TypedValue((int)DxfCode.ExtendedDataLayerName, "0"),
                    new TypedValue((int)DxfCode.ExtendedDataReal, 1.23479137438413E+40),
                    new TypedValue((int)DxfCode.ExtendedDataInteger16, 32767),
                    new TypedValue((int)DxfCode.ExtendedDataInteger32, 32767),
                    new TypedValue((int)DxfCode.ExtendedDataScale, 10),
                    new TypedValue((int)DxfCode.ExtendedDataWorldXCoordinate, new Point3d(10, 10, 0)));
                //将新建的扩展数据附加到所选择的实体中
                circ.XData = rb;
                trans.Commit();
            }
        }
Ejemplo n.º 27
0
 public static void SetNodeId(this DBPoint pt, Database db, int id)
 {
     using (Transaction tr = db.TransactionManager.StartTransaction())
     {
         RegAppTable acRegAppTbl = tr.GetObject(db.RegAppTableId, OpenMode.ForRead) as RegAppTable;
         using (RegAppTableRecord acRegAppTblRec = new RegAppTableRecord())
         {
             acRegAppTblRec.Name = "HKB";
             tr.GetObject(db.RegAppTableId, OpenMode.ForWrite);
             acRegAppTbl.Add(acRegAppTblRec);
             tr.AddNewlyCreatedDBObject(acRegAppTblRec, true);
         }
         using (ResultBuffer rb = new ResultBuffer())
         {
             rb.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "HKB"));
             rb.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, id));
             pt.XData = rb;
         }
     }
 }
Ejemplo n.º 28
0
        public Poze()
        {
            civDoc = CivilApplication.ActiveDocument;
            db     = acadDoc.Database;
            ed     = acadDoc.Editor;
            //trans = db.TransactionManager.StartTransaction();
            using (trans = db.TransactionManager.StartTransaction())
            {
                idAxuri = civDoc.GetAlignmentIds();
                InitializeComponent();
                imagini      = new SortedDictionary <int, string>();
                imaginiCheie = new SortedDictionary <int, string>();
                listaFisiere = new List <string>();

                ActualizeazaAxuri();
                //comboBoxAx.SelectedIndex = 0;

                RegAppTable rat = (RegAppTable)trans.GetObject(db.RegAppTableId, OpenMode.ForWrite, false);
                if (!rat.Has("OVIDIU"))
                {
                    //rat.UpgradeOpen();
                    RegAppTableRecord ratr = new RegAppTableRecord();
                    ratr.Name = "OVIDIU";
                    rat.Add(ratr);
                    trans.AddNewlyCreatedDBObject(ratr, true);
                }
                trans.Commit();
            }

            //Instalare carlig pentru soarece
            MH.RightButtonDown += MH_RightButtonDown;
            MH.LeftButtonDown  += MH_LeftButtonDown;
            if (checkBoxSincr.Checked)
            {
                MH.Install();
            }

            //HookManager.MouseClick += HookManager_MouseClick;
            //SelectieDirector();
            //AfisarePoze();
        }
        private void AddRegAppKey(Document doc)
        {
            using (Transaction trans = doc.TransactionManager.StartTransaction())
            {
                RegAppTable regTable = (RegAppTable)trans.GetObject(doc.Database.RegAppTableId, OpenMode.ForRead);

                if (!regTable.Has("JPP"))
                {
                    regTable.UpgradeOpen();

                    // Add the application names that would be used to add Xdata
                    RegAppTableRecord app = new RegAppTableRecord();
                    app.Name = "JPP";

                    regTable.Add(app);
                    trans.AddNewlyCreatedDBObject(app, true);

                    trans.Commit();
                }
            }
        }
Ejemplo n.º 30
0
        // Set the "pipe radius" in the XData of a particular object

        public static void SetPipeRadiusOnObject(
            Transaction tr, DBObject obj, double radius
            )
        {
            Database db = obj.Database;

            // Make sure the application is registered
            // (we could separate this out to be called
            // only once for a set of operations)

            RegAppTable rat =
                (RegAppTable)tr.GetObject(
                    db.RegAppTableId,
                    OpenMode.ForRead
                    );

            if (!rat.Has(regAppName))
            {
                rat.UpgradeOpen();
                RegAppTableRecord ratr = new RegAppTableRecord();
                ratr.Name = regAppName;
                rat.Add(ratr);
                tr.AddNewlyCreatedDBObject(ratr, true);
            }

            // Create the XData and set it on the object

            ResultBuffer rb =
                new ResultBuffer(
                    new TypedValue(
                        (int)DxfCode.ExtendedDataRegAppName, regAppName
                        ),
                    new TypedValue(
                        (int)DxfCode.ExtendedDataReal, radius
                        )
                    );

            obj.XData = rb;
            rb.Dispose();
        }