Ejemplo n.º 1
0
 public void UpdateSave(ObjectId TableID, int UpdateNum)
 {
     if (TableID == ObjectId.Null)
     {
         return;
     }
     using (Transaction trans = db.TransactionManager.StartTransaction())
     {
         try
         {
             DataTable dt   = (DataTable)trans.GetObject(TableID, OpenMode.ForWrite);
             DataCell  Cell = new DataCell();
             Cell.SetInteger(UpdateNum);
             dt.SetCellAt(0, 0, Cell);
             trans.Commit();
         }
         catch (Autodesk.AutoCAD.Runtime.Exception EX)
         {
             ed.WriteMessage("\n出错了!{0}", EX.ToString());
         }
         finally
         {
             trans.Dispose();
         }
     }
 }
Ejemplo n.º 2
0
        public ObjectId CreateZBDic()
        {
            ObjectId     TableID = ObjectId.Null;
            const string DicName = "GCLZBConfig";

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    DBDictionary dd = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                    if (dd.Contains(DicName))
                    {
                        TableID = dd.GetAt(DicName);
                    }
                    else
                    {
                        DataTable dt = new DataTable();
                        dt.TableName = DicName;
                        dt.AppendColumn(CellType.Double, "TextHeight");
                        dt.AppendColumn(CellType.Integer, "HeightOderOfMagnitude");
                        DataCellCollection Row = new DataCellCollection();
                        DataCell           TH  = new DataCell();
                        DataCell           HM  = new DataCell();

                        PromptDoubleOptions doubleopts = new PromptDoubleOptions("\n输入字高:");
                        doubleopts.AllowNegative = false;
                        doubleopts.AllowZero     = false;
                        PromptDoubleResult doubleresult = ed.GetDouble(doubleopts);
                        if (doubleresult.Status == PromptStatus.OK)
                        {
                            TH.SetDouble(doubleresult.Value);

                            PromptIntegerOptions intopts = new PromptIntegerOptions("\n输入高程数量级(高程在10以内为0,100以内为1,以此类推):");
                            intopts.AllowNegative = false;
                            PromptIntegerResult intresult = ed.GetInteger(intopts);
                            if (intresult.Status == PromptStatus.OK)
                            {
                                HM.SetInteger(intresult.Value);

                                Row.Add(TH);
                                Row.Add(HM);
                                dt.AppendRow(Row, true);
                                dd.UpgradeOpen();
                                TableID = dd.SetAt(DicName, dt);
                                trans.AddNewlyCreatedDBObject(dt, true);
                            }
                        }
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception EX)
                {
                    ed.WriteMessage("出错了!" + EX.ToString());
                }
                trans.Commit();
            }
            return(TableID);
        }
Ejemplo n.º 3
0
        public void ChangeZBConfig(ObjectId tableID)
        {
            DataCellCollection Row = new DataCellCollection();
            DataCell           TH  = new DataCell();
            DataCell           HM  = new DataCell();

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    DataTable           dt         = (DataTable)trans.GetObject(tableID, OpenMode.ForWrite);
                    PromptDoubleOptions doubleopts = new PromptDoubleOptions("\n输入字高:");
                    doubleopts.AllowNone       = true;
                    doubleopts.AllowNegative   = false;
                    doubleopts.AllowZero       = false;
                    doubleopts.UseDefaultValue = true;
                    doubleopts.DefaultValue    = (double)dt.GetCellAt(0, 0).Value;
                    PromptDoubleResult doubleresult = ed.GetDouble(doubleopts);
                    if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None)
                    {
                        TH.SetDouble(doubleresult.Value);

                        PromptIntegerOptions intopts = new PromptIntegerOptions("\n输入高程数量级(高程在10以内为0,100以内为1,以此类推):");
                        intopts.AllowNone       = true;
                        intopts.AllowNegative   = false;
                        intopts.UseDefaultValue = true;
                        intopts.DefaultValue    = (int)dt.GetCellAt(0, 1).Value;
                        PromptIntegerResult intresult = ed.GetInteger(intopts);
                        if (intresult.Status == PromptStatus.OK || intresult.Status == PromptStatus.None)
                        {
                            HM.SetInteger(intresult.Value);

                            Row.Add(TH);
                            Row.Add(HM);
                            dt.SetRowAt(0, Row, true);
                        }
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception EX)
                {
                    ed.WriteMessage("出错了!" + EX.ToString());
                }
                trans.Commit();
            }
        }
Ejemplo n.º 4
0
        public void cmdAddDataTableData()
        {
            var doc = AcApp.DocumentManager.MdiActiveDocument;
            var ed  = doc.Editor;
            var db  = doc.Database;

            var result = ed.GetEntity("\nPlease select an entity to store data");

            if (result.Status != PromptStatus.OK)
            {
                return;
            }

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var entity = tr.GetObject(result.ObjectId, OpenMode.ForWrite) as Entity;
                if (entity.ExtensionDictionary.IsNull)
                {
                    entity.CreateExtensionDictionary();
                }
                var extDictId = entity.ExtensionDictionary;
                var extDict   = tr.GetObject(extDictId, OpenMode.ForWrite) as DBDictionary;

                var dataTable = new DataTable();
                dataTable.AppendColumn(CellType.Integer, "IntValue");
                dataTable.AppendColumn(CellType.CharPtr, "Text");
                var rowData  = new DataCellCollection();
                var intValue = new DataCell();
                intValue.SetInteger(123);
                rowData.Add(intValue);
                var textValue = new DataCell();
                textValue.SetString("this is a text");
                rowData.Add(textValue);
                dataTable.AppendRow(rowData, true);

                extDict["MyData"] = dataTable;
                tr.AddNewlyCreatedDBObject(dataTable, true);

                tr.Commit();
            }
        }
Ejemplo n.º 5
0
        public ObjectId InitialSave()
        {
            ObjectId TableID = ObjectId.Null;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    DBDictionary dd = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                    if (dd.Contains(SaveName))
                    {
                        TableID = dd.GetAt(SaveName);
                    }
                    else
                    {
                        DataTable dt = new DataTable();
                        dt.TableName = SaveName;
                        dt.AppendColumn(CellType.Integer, SaveKey);
                        DataCellCollection Row  = new DataCellCollection();
                        DataCell           Cell = new DataCell();
                        Cell.SetInteger(InitialNum);
                        Row.Add(Cell);
                        dt.AppendRow(Row, true);
                        dd.UpgradeOpen();
                        TableID = dd.SetAt(SaveName, dt);
                        trans.AddNewlyCreatedDBObject(dt, true);
                    }
                    trans.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception EX)
                {
                    ed.WriteMessage("\n出错了!{0}", EX.ToString());
                }
                finally
                {
                    trans.Dispose();
                }
            }

            return(TableID);
        }
Ejemplo n.º 6
0
        public ObjectId CreateCeDic()            //创建存储于NameObjectsDictionary的DataTable用于保存程序设置
        //弯管类型存储在(0,0),半径在(0,1),半径倍率在(0,2),字高在(0,3),是否显示节点坐标(0,4)
        {
            const string dicname = "GCLCurveElementsConfig";
            ObjectId     DicId   = ObjectId.Null;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    DBDictionary dd = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                    if (dd.Contains(dicname))
                    {
                        DicId = dd.GetAt(dicname);
                    }
                    else
                    {
                        DataTable dt = new DataTable();
                        dt.TableName = dicname;
                        dt.AppendColumn(CellType.Integer, "Type");
                        dt.AppendColumn(CellType.Double, "Diameter");
                        dt.AppendColumn(CellType.Double, "DiameterMultiple");
                        dt.AppendColumn(CellType.Double, "TextH");
                        DataCellCollection Row              = new DataCellCollection();
                        DataCell           Type             = new DataCell();
                        DataCell           Diameter         = new DataCell();
                        DataCell           DiameterMultiple = new DataCell();
                        DataCell           TextH            = new DataCell();

                        PromptKeywordOptions keyopts   = new PromptKeywordOptions("\n输入弯管的类型[冷弯(C)/热煨(H)/弹性敷设(E)]:", "C H E");
                        PromptResult         keyresult = ed.GetKeywords(keyopts);
                        if (keyresult.Status == PromptStatus.OK)
                        {
                            switch (keyresult.StringResult)
                            {
                            case "C":
                                Type.SetInteger((int)TypeOfCurveElements.cold);
                                break;

                            case "H":
                                Type.SetInteger((int)TypeOfCurveElements.hot);
                                break;

                            case "E":
                                Type.SetInteger((int)TypeOfCurveElements.elastic);
                                break;
                            }
                            PromptDoubleOptions doubleopts = new PromptDoubleOptions("\n输入弯管外径(mm):");
                            doubleopts.AllowNegative = false;
                            doubleopts.AllowZero     = false;

                            PromptDoubleResult doubleresult = ed.GetDouble(doubleopts);
                            if (doubleresult.Status == PromptStatus.OK)
                            {
                                Diameter.SetDouble(doubleresult.Value);

                                doubleopts.Message = "\n输入管径倍率:";
                                doubleresult       = ed.GetDouble(doubleopts);
                                if (doubleresult.Status == PromptStatus.OK)
                                {
                                    DiameterMultiple.SetDouble(doubleresult.Value);

                                    doubleopts.Message = "\n输入字高:";
                                    doubleresult       = ed.GetDouble(doubleopts);
                                    if (doubleresult.Status == PromptStatus.OK)
                                    {
                                        TextH.SetDouble(doubleresult.Value);
                                        Row.Add(Type);
                                        Row.Add(Diameter);
                                        Row.Add(DiameterMultiple);
                                        Row.Add(TextH);
                                        dt.AppendRow(Row, true);

                                        dd.UpgradeOpen();
                                        DicId = dd.SetAt(dicname, dt);
                                        trans.AddNewlyCreatedDBObject(dt, true);
                                    }
                                }
                            }
                        }
                    }


                    trans.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception EX)
                {
                    ed.WriteMessage("\n出错了!" + EX.ToString());
                }
            }
            return(DicId);
        }
Ejemplo n.º 7
0
        public void ChangeConfig(ObjectId tableID)           //修改程序设置信息
        {
            DataCellCollection Row              = new DataCellCollection();
            DataCell           Type             = new DataCell();
            DataCell           Diameter         = new DataCell();
            DataCell           DiameterMultiple = new DataCell();
            DataCell           TextH            = new DataCell();

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    DataTable dt = (DataTable)trans.GetObject(tableID, OpenMode.ForWrite);



                    PromptKeywordOptions keyopts = new PromptKeywordOptions("\n输入弯管的类型[冷弯(C)/热煨(H)/弹性敷设(E)]:", "C H E");
                    keyopts.AllowNone = true;

                    switch ((int)dt.GetCellAt(0, 0).Value)
                    {
                    case 1:
                        keyopts.Keywords.Default = "C";
                        break;

                    case 2:
                        keyopts.Keywords.Default = "H";
                        break;

                    case 3:
                        keyopts.Keywords.Default = "E";
                        break;
                    }

                    PromptResult keyresult = ed.GetKeywords(keyopts);
                    if (keyresult.Status == PromptStatus.OK || keyresult.Status == PromptStatus.None)
                    {
                        switch (keyresult.StringResult)
                        {
                        case "C":
                            Type.SetInteger((int)TypeOfCurveElements.cold);
                            break;

                        case "H":
                            Type.SetInteger((int)TypeOfCurveElements.hot);
                            break;

                        case "E":
                            Type.SetInteger((int)TypeOfCurveElements.elastic);
                            break;
                        }
                        PromptDoubleOptions doubleopts = new PromptDoubleOptions("\n输入弯管外径(mm):");
                        doubleopts.AllowNone       = true;
                        doubleopts.AllowNegative   = false;
                        doubleopts.AllowZero       = false;
                        doubleopts.UseDefaultValue = true;
                        doubleopts.DefaultValue    = (double)dt.GetCellAt(0, 1).Value;

                        PromptDoubleResult doubleresult = ed.GetDouble(doubleopts);
                        if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None)
                        {
                            Diameter.SetDouble(doubleresult.Value);

                            doubleopts.Message      = "\n输入管径倍率:";
                            doubleopts.DefaultValue = (double)dt.GetCellAt(0, 2).Value;
                            doubleresult            = ed.GetDouble(doubleopts);
                            if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None)
                            {
                                DiameterMultiple.SetDouble(doubleresult.Value);

                                doubleopts.Message      = "\n输入字高:";
                                doubleopts.DefaultValue = (double)dt.GetCellAt(0, 3).Value;
                                doubleresult            = ed.GetDouble(doubleopts);
                                if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None)
                                {
                                    TextH.SetDouble(doubleresult.Value);
                                    Row.Add(Type);
                                    Row.Add(Diameter);
                                    Row.Add(DiameterMultiple);
                                    Row.Add(TextH);
                                    dt.SetRowAt(0, Row, true);
                                }
                            }
                        }
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception EX)
                {
                    ed.WriteMessage("\n出错了!" + EX.ToString());
                }
                trans.Commit();
            }
        }