Example #1
0
        public void GETXDATA()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("获取扩展数据XDATA\n");
            PromptEntityOptions entOps = new PromptEntityOptions("请选择要打开的对象\n");
            PromptEntityResult  entRes = ed.GetEntity(entOps);

            if (entRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("选择对象失败,退出"); return;
            }
            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Entity       ent    = (Entity)tr.GetObject(entRes.ObjectId, OpenMode.ForRead);
                ResultBuffer resBuf = ent.XData;
                if (resBuf != null)
                {
                    var iter = resBuf.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        TypedValue tmpVal = (TypedValue)iter.Current;
                        ed.WriteMessage(tmpVal.TypeCode.ToString() + ":");
                        ed.WriteMessage(tmpVal.Value.ToString() + "\n");
                    }
                }
            }
        }
Example #2
0
        public void ReadData()
        {
            Document           doc    = Application.DocumentManager.MdiActiveDocument;
            Database           db     = doc.Database;
            Editor             ed     = doc.Editor;
            Entity             entity = null;
            PromptEntityResult ent    = ed.GetEntity("\n选择要读取数据的对象");

            if (ent.Status == PromptStatus.OK)
            {
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    entity = (Entity)trans.GetObject(ent.ObjectId, OpenMode.ForRead, true);

                    ResultBuffer resBuf = entity.XData;
                    TypedValue[] tv     = resBuf.AsArray();

                    if (resBuf != null)
                    {
                        //
                        IEnumerator iter = resBuf.GetEnumerator();
                        while (iter.MoveNext())
                        {
                            TypedValue tmpVal = (TypedValue)iter.Current;
                            ed.WriteMessage(tmpVal.TypeCode.ToString() + ":");
                            ed.WriteMessage(tmpVal.Value.ToString() + "\n");
                        }
                    }
                    DBDictionary NOD = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead, false);
                }
            }
        }
Example #3
0
        public DBObjectCollection Collection()
        {
            Document           doc              = Application.DocumentManager.MdiActiveDocument;
            Database           db               = doc.Database;
            Editor             ed               = doc.Editor;
            Entity             entity           = null;
            DBObjectCollection EntityCollection = new DBObjectCollection();
            //定义 过滤条件
            TypedValue value1 = new TypedValue((int)DxfCode.LayerName, "JMD");

            TypedValue[] filter = new TypedValue[1];
            filter[0] = value1;
            SelectionFilter filterLayer = new SelectionFilter(filter);

            PromptSelectionResult ents = ed.GetSelection(filterLayer);

            if (ents.Status == PromptStatus.OK)
            {
                using (Transaction transantion = db.TransactionManager.StartTransaction())
                {
                    SelectionSet SS = ents.Value;
                    foreach (ObjectId id in SS.GetObjectIds())
                    {
                        entity = (Entity)transantion.GetObject(id, OpenMode.ForRead, true);

                        if (entity != null)
                        {
                            EntityCollection.Add(entity);

                            ResultBuffer resBuf = entity.XData;
                            if (resBuf != null)
                            {
                                //
                                IEnumerator iter = resBuf.GetEnumerator();
                                while (iter.MoveNext())
                                {
                                    TypedValue tmpVal = (TypedValue)iter.Current;
                                    ed.WriteMessage(tmpVal.TypeCode.ToString() + ":");
                                    ed.WriteMessage(tmpVal.Value.ToString() + "\n");
                                }
                            }

                            setPolyeText(doc, entity);
                        }
                    }
                    transantion.Commit();
                }
            }
            return(EntityCollection);
        }
Example #4
0
 public void CheckJG(Entity entity, Entity dbText)
 {
     if (entity != null)
     {
         Document     mdiActiveDocument = Application.DocumentManager.MdiActiveDocument;
         Editor       editor            = mdiActiveDocument.Editor;
         ResultBuffer xData             = entity.XData;
         Point3d      textPoint3d       = this.GetTextPoint3d(dbText);
         if (textPoint3d.X != 0.0)
         {
             string dbText2 = this.GetDbText(dbText);
             if (!(dbText2 == "num"))
             {
                 if (xData != null)
                 {
                     IEnumerator enumerator = xData.GetEnumerator();
                     while (enumerator.MoveNext())
                     {
                         TypedValue typedValue = (TypedValue)enumerator.Current;
                         editor.WriteMessage(typedValue.Value.ToString() + "\n");
                         if (typedValue.Value.ToString() == "141111")
                         {
                             editor.WriteMessage("结构" + dbText2 + "\n");
                             if (dbText2 != "砼")
                             {
                                 this.CreateCircle(textPoint3d, 1);
                             }
                         }
                         else if (typedValue.Value.ToString() == "141121")
                         {
                             editor.WriteMessage("结构" + dbText2 + "\n");
                             if (dbText2 != "砖")
                             {
                                 this.CreateCircle(textPoint3d, 1);
                             }
                         }
                         else if (typedValue.Value.ToString() == "141101")
                         {
                             if (dbText2.Contains("砖") || dbText2.Contains("砼"))
                             {
                                 this.CreateCircle(textPoint3d, 1);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #5
0
        public static System.Data.DataTable GetAllPolylineNums()
        {
            System.Data.DataTable table = new System.Data.DataTable("编码");
            table.Columns.Add(new System.Data.DataColumn(("多段线id"), typeof(string)));
            table.Columns.Add(new System.Data.DataColumn(("个体编码"), typeof(string)));
            table.Columns.Add(new System.Data.DataColumn(("个体要素"), typeof(string)));
            table.Columns.Add(new System.Data.DataColumn(("个体名称"), typeof(string)));
            table.Columns.Add(new System.Data.DataColumn(("数量"), typeof(string)));
            table.Columns.Add(new System.Data.DataColumn(("个体阶段"), typeof(string)));

            System.Data.DataColumn column;
            System.Data.DataRow    row;

            Document     doc            = Application.DocumentManager.MdiActiveDocument;
            Editor       ed             = doc.Editor;
            Database     db             = doc.Database;
            DocumentLock m_DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument();

            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId layerId in LayersToList(db))
                    {
                        LayerTableRecord layer = tr.GetObject(layerId, OpenMode.ForRead) as LayerTableRecord;

                        TypedValue[] filList = new TypedValue[1] {
                            new TypedValue((int)DxfCode.LayerName, layer.Name)
                        };
                        SelectionFilter sfilter = new SelectionFilter(filList);

                        PromptSelectionResult result = ed.SelectAll(sfilter);
                        if (result.Status == PromptStatus.OK)
                        {
                            SelectionSet acSSet = result.Value;
                            foreach (ObjectId id in acSSet.GetObjectIds())
                            {
                                DBObject obj = id.GetObject(OpenMode.ForRead); //以读的方式打开对象

                                ObjectId dictId = obj.ExtensionDictionary;     //获取对象的扩展字典的id

                                Entity ent1 = tr.GetObject(id, OpenMode.ForRead) as Entity;
                                if (ent1 is Polyline && !dictId.IsNull)
                                {
                                    DBDictionary dict = dictId.GetObject(OpenMode.ForRead) as DBDictionary;//获取对象的扩展字典
                                    if (!dict.Contains("polylineNumber"))
                                    {
                                        continue;//如果扩展字典中没有包含指定关键 字的扩展记录,则返回null;
                                    }
                                    //先要获取对象的扩展字典或图形中的有名对象字典,然后才能在字典中获取要查询的扩展记录
                                    ObjectId     xrecordId = dict.GetAt("polylineNumber");                     //获取扩展记录对象的id
                                    Xrecord      xrecord   = xrecordId.GetObject(OpenMode.ForRead) as Xrecord; //根据id获取扩展记录对象
                                    ResultBuffer resBuf    = xrecord.Data;

                                    ResultBufferEnumerator rator = resBuf.GetEnumerator();
                                    int i = 0;

                                    List <string> values = new List <string>();
                                    while (rator.MoveNext())
                                    {
                                        TypedValue re = rator.Current;
                                        values.Add((string)re.Value);
                                    }

                                    bool hasData = false;
                                    foreach (System.Data.DataRow item in table.Rows)
                                    {
                                        if ((string)item["个体编码"] == values[0] && (string)item["个体要素"] == values[1] && (string)item["个体名称"] == values[2] && (string)item["个体阶段"] == values[3])
                                        {
                                            item["多段线id"] += id.Handle.Value.ToString() + ",";
                                            int count = 0;
                                            int.TryParse((string)item["数量"], out count);
                                            item["数量"] = count + 1;
                                            hasData    = true;
                                            break;
                                        }
                                    }
                                    if (!hasData)
                                    {
                                        row          = table.NewRow();
                                        row["多段线id"] = id.Handle.Value.ToString() + ",";
                                        row["数量"]    = 1;
                                        while (rator.MoveNext())
                                        {
                                            TypedValue re = rator.Current;
                                            if (i == 0)
                                            {
                                                row["个体编码"] = re.Value;
                                            }
                                            if (i == 1)
                                            {
                                                row["个体要素"] = re.Value;
                                            }
                                            if (i == 2)
                                            {
                                                row["个体名称"] = re.Value;
                                            }
                                            if (i == 3)
                                            {
                                                row["个体阶段"] = re.Value;
                                            }
                                            i++;
                                        }
                                        table.Rows.Add(row);
                                    }
                                    resBuf.Dispose();
                                    xrecord.Dispose();
                                    dict.Dispose();
                                }
                                ent1.Dispose();
                                obj.Dispose();
                            }
                        }

                        layer.Dispose();
                    }
                    tr.Commit();
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }
            finally
            {
                m_DocumentLock.Dispose();
            }
            return(table);
        }
Example #6
0
        public static System.Data.DataTable GetAllPolylineNumsEx(Polyline line)
        {
            System.Data.DataTable table = new System.Data.DataTable("编码");
            table.Columns.Add(new System.Data.DataColumn(("多段线id"), typeof(string)));
            table.Columns.Add(new System.Data.DataColumn(("个体编码"), typeof(string)));
            table.Columns.Add(new System.Data.DataColumn(("个体要素"), typeof(string)));
            table.Columns.Add(new System.Data.DataColumn(("个体名称"), typeof(string)));
            table.Columns.Add(new System.Data.DataColumn(("个体阶段"), typeof(string)));

            System.Data.DataColumn column;
            System.Data.DataRow    row;

            try
            {
                ObjectId dictId = line.ExtensionDictionary;//获取对象的扩展字典的id
                if (!dictId.IsNull)
                {
                    DBDictionary dict = dictId.GetObject(OpenMode.ForRead) as DBDictionary;//获取对象的扩展字典
                    if (!dict.Contains("polylineNumber"))
                    {
                        return(null);//如果扩展字典中没有包含指定关键 字的扩展记录,则返回null;
                    }
                    //先要获取对象的扩展字典或图形中的有名对象字典,然后才能在字典中获取要查询的扩展记录
                    ObjectId     xrecordId = dict.GetAt("polylineNumber");                     //获取扩展记录对象的id
                    Xrecord      xrecord   = xrecordId.GetObject(OpenMode.ForRead) as Xrecord; //根据id获取扩展记录对象
                    ResultBuffer resBuf    = xrecord.Data;

                    ResultBufferEnumerator rator = resBuf.GetEnumerator();
                    int i = 0;
                    row          = table.NewRow();
                    row["多段线id"] = line.Id.Handle.Value.ToString();

                    while (rator.MoveNext())
                    {
                        TypedValue re = rator.Current;
                        if (i == 0)
                        {
                            row["个体编码"] = re.Value;
                        }
                        if (i == 1)
                        {
                            row["个体要素"] = re.Value;
                        }
                        if (i == 2)
                        {
                            row["个体名称"] = re.Value;
                        }
                        if (i == 3)
                        {
                            row["个体阶段"] = re.Value;
                        }
                        i++;
                    }

                    table.Rows.Add(row);
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }
            return(table);
        }