Example #1
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);
        }
        public void Map_StateUnderTest_ExpectedBehavior_Longitude()
        {
            // Arrange
            DegreeToDecimalLatLongMapper degreeToDecimalLatLongMapper = this.CreateDegreeToDecimalLatLongMapper();
            DataCellCollection           sourceRows = new DataCellCollection();

            sourceRows.Add(new DataCell(new LumenWorks.Framework.IO.Csv.Column()
            {
                Name = Constants.columnkey
            }, "", "3519S 14804E"));

            string             columnkey    = Constants.longitudeKey;
            string             value        = "3519S 14804E";
            DataCellCollection currentState = new DataCellCollection();

            Dictionary <string, string> Context = new Dictionary <string, string>();
            // Act
            List <DataCell> result = degreeToDecimalLatLongMapper.Map(
                sourceRows,
                columnkey,
                value,
                Context,
                currentState);

            // Assert 148.066666666667
            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0].Value == "148.066666666667");
        }
Example #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();
            }
        }
        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();
            }
        }
Example #5
0
        public void AddData()
        {
            DataTable dt = new DataTable();

            dt.TableName = "ParameterTable";
            dt.AppendColumn(CellType.CharPtr, "Name");
            dt.AppendColumn(CellType.CharPtr, "Meterial");
            dt.AppendColumn(CellType.CharPtr, "Parameter");
            DataCellCollection Row       = new DataCellCollection();
            DataCell           Name      = new DataCell();
            DataCell           Meterial  = new DataCell();
            DataCell           Parameter = new DataCell();

            Name.SetString("工字钢");
            Meterial.SetString("Q235B");
            Parameter.SetString("200*200*32*25");
            Row.Add(Name);
            Row.Add(Meterial);
            Row.Add(Parameter);
            dt.AppendRow(Row, true);
            Document           doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database           db  = doc.Database;
            Editor             ed  = doc.Editor;
            PromptEntityResult ent = ed.GetEntity("\n选择要写数据的对象");

            if (ent.Status == PromptStatus.OK)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    Entity entity = (Entity)tr.GetObject(ent.ObjectId, OpenMode.ForWrite, true);
                    if (entity.ExtensionDictionary == new ObjectId())
                    {
                        entity.CreateExtensionDictionary();
                    }
                    DBDictionary extensionDic = (DBDictionary)tr.GetObject(entity.ExtensionDictionary,
                                                                           OpenMode.ForWrite, false);
                    extensionDic.SetAt("ParameterTable", dt);
                    tr.Commit();
                }
            }
        }
Example #6
0
        private DataCellCollection BuildRow(string[] items)
        {
            DataCellCollection row = new DataCellCollection();

            if (items.Length != this.Columns.Count)
            {
                this._logger.Log($"Columns & Values are not same {string.Join(",",items) }", EventLevel.Error, new DataMisalignedException("Columns & Values are not same"));
                //  return row;
            }
            for (int i = 0; i < this.Columns.Count && i < items.Length; i++)
            {
                row.Add(new DataCell(this.Columns[i], "", items[i]));
            }
            return(this._dataCleaner.CleanRow(row));
        }
Example #7
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);
        }
Example #8
0
        private string createFlag(Document doc)
        {
            string   dbnamestr = null;
            Database db        = doc.Database;
            DBPoint  flag      = null;

            //创建点
            using (Transaction tm = db.TransactionManager.StartTransaction())
            {
                flag         = new DBPoint(new Point3d(0, 0, 0));
                flag.Layer   = "-735";
                flag.Visible = false;

                BlockTable       bt  = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                btr.AppendEntity(flag);

                tm.AddNewlyCreatedDBObject(flag, true);
                tm.Commit();
            }

            ////扩展数据
            Guid      guid = Guid.NewGuid();
            DataTable dt   = new DataTable();

            dt.TableName = "database flag";
            dt.AppendColumn(CellType.Bool, "hasDatabase");
            dt.AppendColumn(CellType.CharPtr, "databaseName");
            DataCellCollection row          = new DataCellCollection();
            DataCell           hasDatabase  = new DataCell();
            DataCell           databaseName = new DataCell();

            hasDatabase.SetBool(true);
            dbnamestr = guid.ToString();
            databaseName.SetString(dbnamestr);
            row.Add(hasDatabase);
            row.Add(databaseName);
            dt.AppendRow(row, true);

            using (Transaction tm = db.TransactionManager.StartTransaction())
            {
                Entity entity = (Entity)tm.GetObject(flag.ObjectId, OpenMode.ForWrite, false);

                if (entity.ExtensionDictionary == new ObjectId())
                {
                    entity.CreateExtensionDictionary();
                }

                DBDictionary extensionDic = (DBDictionary)tm.GetObject(flag.ExtensionDictionary, OpenMode.ForWrite, false);
                extensionDic.SetAt("database flag", dt);
                tm.AddNewlyCreatedDBObject(dt, true);

                ////锁定,冻结图层
                LayerTable       lt  = (LayerTable)tm.GetObject(db.LayerTableId, OpenMode.ForRead, false);
                LayerTableRecord ltr = (LayerTableRecord)tm.GetObject(lt["-735"], OpenMode.ForWrite, false);
                ltr.IsFrozen = true;

                tm.Commit();
            }
            return(dbnamestr);
        }
Example #9
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);
        }
Example #10
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();
            }
        }