Exemplo n.º 1
0
        // заполнить таблицу свойств по объектам
        public void Fill()
        {
            try
            {
                doc.ImpliedSelectionChanged += new EventHandler(doc_EntitySelectionChanged);
                db.ObjectAppended           += new ObjectEventHandler(db_AddEntityRow);

                this.Clear();

                // начинаем транзакцию
                using (Transaction trn = db.TransactionManager.StartTransaction())
                {
                    // Открываем Block table record для чтения
                    BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;

                    foreach (ObjectId btrId in bt)
                    {
                        BlockTableRecord           btr    = btrId.GetObject(OpenMode.ForRead) as BlockTableRecord;
                        BlockTableRecordEnumerator enumer = btr.GetEnumerator();
                        while (enumer.MoveNext())
                        {
                            Entity ent = trn.GetObject(enumer.Current, OpenMode.ForRead) as Entity;

                            // событие на изменение объекта
                            this.Add(new PropertyData(ref ent, ent_ModifEntityRow));
                        }
                    }
                    trn.Commit();
                }
            }
            catch (System.Exception ex)
            {
                doc.Editor.WriteMessage("Exception: " + ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Adds the block attributes.
        /// </summary>
        /// <param name="blockRef">The block ref.</param>
        /// <param name="blockDefinition">The block definition.</param>
        /// <param name="attributeTagValue">The attribute tag value.</param>
        /// <param name="tm">The tm.</param>
        private static void AddBlockAttributes(BlockReference blockRef, BlockTableRecord blockDefinition,
                                               Hashtable attributeTagValue, TransactionManager tm)
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start AddBlockAttributes");
            var         m = blockRef.BlockTransform;
            IEnumerator i;

            i = blockDefinition.GetEnumerator();
            while (i.MoveNext())
            {
                var obj = tm.GetObject((ObjectId)i.Current, OpenMode.ForRead, false);
                if (typeof(AttributeDefinition) == obj.GetType())
                {
                    var attDef = (AttributeDefinition)obj;
                    if (!attDef.Constant)
                    {
                        var attRef = new AttributeReference();
                        attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform);
                        if (attributeTagValue.ContainsKey(attRef.Tag))
                        {
                            attRef.TextString = (string)attributeTagValue[attRef.Tag];
                        }

                        attRef.Position = attDef.Position.TransformBy(m);
                        blockRef.AttributeCollection.AppendAttribute(attRef);
                        tm.AddNewlyCreatedDBObject(attRef, true);
                    }
                }
            }
            PGA.MessengerManager.MessengerManager.AddLog("End AddBlockAttributes");
        }
Exemplo n.º 3
0
        public void InsertBlockRefWithAtt(string blockName, Point3d point, Scale3d scale, double rotateAngle, string roomnumber)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                if (!bt.Has(blockName))
                {
                    return;
                }
                BlockTableRecord blockwithatt = (BlockTableRecord)trans.GetObject(bt[blockName], OpenMode.ForRead);
                BlockReference   blockRef     = new BlockReference(point, bt[blockName]);
                BlockTableRecord btr          = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                blockRef.ScaleFactors = scale;
                blockRef.Rotation     = rotateAngle;
                btr.AppendEntity(blockRef);
                trans.AddNewlyCreatedDBObject(blockRef, true);
                //获取blockName块的遍历器,以实现对块中对象的访问
                BlockTableRecordEnumerator iterator = blockwithatt.GetEnumerator();
                //如果blockName块包含属性
                if (blockwithatt.HasAttributeDefinitions)
                {
                    //利用块遍历器对块中的对象进行遍历
                    while (iterator.MoveNext())
                    {
                        //获取块遍历器当前指向的块中的对象
                        AttributeDefinition attdef = trans.GetObject(iterator.Current, OpenMode.ForRead) as AttributeDefinition;
                        //定义一个新的属性参照对象
                        AttributeReference att = new AttributeReference();
                        //判断块遍历器当前指向的块中的对象是否为属性定义
                        if (attdef != null)
                        {
                            //从属性定义对象中继承相关的属性到属性参照对象中
                            att.SetAttributeFromBlock(attdef, blockRef.BlockTransform);
                            //设置属性参照对象的位置为属性定义的位置+块参照的位置
                            att.Position = attdef.Position + blockRef.Position.GetAsVector();
                            //判断属性定义的名称
                            switch (attdef.Tag)
                            {
                            //如果为"NUMBER",则设置块参照的属性值
                            case "NUMBER":
                                att.TextString = roomnumber;
                                break;
                            }
                            //判断块参照是否可写,如不可写,则切换为可写状态
                            if (!blockRef.IsWriteEnabled)
                            {
                                blockRef.UpgradeOpen();
                            }
                            //添加新创建的属性参照
                            blockRef.AttributeCollection.AppendAttribute(att);
                            //通知事务处理添加新创建的属性参照
                            trans.AddNewlyCreatedDBObject(att, true);
                        }
                    }
                }
                trans.Commit();//提交事务处理
            }
        }
Exemplo n.º 4
0
        public static ObjectId[] GetAllPos()
        {
            List <ObjectId> list = new List <ObjectId>();
            Database        db   = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
                    using (BlockTableRecordEnumerator it = btr.GetEnumerator())
                    {
                        while (it.MoveNext())
                        {
                            if (it.Current.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(RebarPos)))
                            {
                                list.Add(it.Current);
                            }
                        }
                    }
                }
                catch (System.Exception)
                {
                    ;
                }
            }
            return(list.ToArray());
        }
Exemplo n.º 5
0
        public static ObjectId[] GetPosWithShape(string shape)
        {
            List <ObjectId> list = new List <ObjectId>();
            Database        db   = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
                    using (BlockTableRecordEnumerator it = btr.GetEnumerator())
                    {
                        while (it.MoveNext())
                        {
                            RebarPos pos = tr.GetObject(it.Current, OpenMode.ForRead) as RebarPos;
                            if (pos != null)
                            {
                                if (pos.Shape == shape)
                                {
                                    list.Add(it.Current);
                                }
                            }
                        }
                    }
                }
                catch (System.Exception)
                {
                    ;
                }
            }
            return(list.ToArray());
        }
Exemplo n.º 6
0
        private void RuttonReplace_Click(object sender, RoutedEventArgs e)
        {
            if (Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.Count > 0)
            {
                Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.CurrentDocument.Editor.WriteMessage("Close the open documents:\n");
                foreach (Document doc in Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager)
                {
                    Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.CurrentDocument.Editor.WriteMessage(doc.Name + "\n");
                }
                return;
            }

            foreach (DWG item in DWGs)
            {
                Database acDb = new Database(false, true);
                using (acDb)
                {
                    acDb.ReadDwgFile(item.Path, FileShare.ReadWrite, false, "");
                    using (Transaction trans = acDb.TransactionManager.StartTransaction())
                    {
                        BlockTable                 bt      = (BlockTable)trans.GetObject(acDb.BlockTableId, OpenMode.ForWrite);
                        BlockTableRecord           ms      = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                        BlockTableRecordEnumerator recEnum = ms.GetEnumerator();

                        while (recEnum.MoveNext())
                        {
                            Entity ent = (Entity)trans.GetObject(recEnum.Current, OpenMode.ForRead);
                            if (ent.GetType() == typeof(BlockReference))
                            {
                                BlockReference blockRef = ent as BlockReference;
                                if (blockRef.Handle == hBlock)
                                {
                                    AttributeCollection attCol = blockRef.AttributeCollection;

                                    foreach (ObjectId att in attCol)
                                    {
                                        using (AttributeReference attRef = trans.GetObject(att, OpenMode.ForWrite) as AttributeReference)
                                        {
                                            if (attRef.Tag == ComboAttribute.SelectedValue.ToString())
                                            {
                                                attRef.TextString = TBReplacement.Text;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        trans.Commit();
                        acDb.SaveAs(item.Path, DwgVersion.Current);
                        item.Check = true;
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void ReplaceBlocks()
        {
            if (Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.Count > 0)
            {
                Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.CurrentDocument.Editor.WriteMessage("Close the open documents:\n");
                foreach (Document doc in Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager)
                {
                    Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.CurrentDocument.Editor.WriteMessage(doc.Name + "\n");
                }
                return;
            }

            foreach (DWG item in DWGs)
            {
                Database acDb = new Database(false, true);
                using (acDb)
                {
                    acDb.ReadDwgFile(item.Path, FileShare.ReadWrite, false, "");
                    using (Transaction trans = acDb.TransactionManager.StartTransaction())
                    {
                        BlockTable                 bt      = (BlockTable)trans.GetObject(acDb.BlockTableId, OpenMode.ForWrite);
                        BlockTableRecord           ms      = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                        BlockTableRecordEnumerator recEnum = ms.GetEnumerator();

                        while (recEnum.MoveNext())
                        {
                            Entity ent = (Entity)trans.GetObject(recEnum.Current, OpenMode.ForWrite);
                            if (ent.GetType() == typeof(BlockReference))
                            {
                                BlockReference blockRef = ent as BlockReference;
                                if (blockRef.Handle.Value.CompareTo(hBlockReplace.Value) == 0)
                                {
                                    using (BlockReference acBlkRef = new BlockReference(blockRef.Position, bt[BlockReplacement]))
                                    {
                                        BlockTableRecord acCurSpaceBlkTblRec;
                                        acCurSpaceBlkTblRec = trans.GetObject(acDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                                        acCurSpaceBlkTblRec.AppendEntity(acBlkRef);
                                        trans.AddNewlyCreatedDBObject(acBlkRef, true);
                                        AddAttributes(acBlkRef);
                                    }
                                    item.Check = true;
                                    blockRef.Erase();
                                    break;
                                }
                            }
                        }
                        trans.Commit();
                        acDb.SaveAs(item.Path, DwgVersion.Current);
                        item.Check = true;
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void ButtonRead_Click(object sender, RoutedEventArgs e)
        {
            foreach (DataRow DR in DT.Rows)
            {
                int      index = 1;
                Database acDb  = new Database(false, true);
                using (acDb)
                {
                    acDb.ReadDwgFile(DR["Filename"].ToString(), FileShare.Read, false, "");
                    using (Transaction trans = acDb.TransactionManager.StartTransaction())
                    {
                        BlockTable                 bt      = (BlockTable)trans.GetObject(acDb.BlockTableId, OpenMode.ForWrite);
                        BlockTableRecord           ms      = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                        BlockTableRecordEnumerator recEnum = ms.GetEnumerator();

                        while (index < DT.Columns.Count - 1)
                        {
                            recEnum.Reset();
                            Handle bHandle   = new Handle(long.Parse(DT.Columns[index].ColumnName.Split('-')[1].ToString()));
                            string blockName = DT.Columns[index].ColumnName.Split('-')[0].ToString();
                            while (recEnum.MoveNext())
                            {
                                Entity ent = (Entity)trans.GetObject(recEnum.Current, OpenMode.ForRead);
                                if (ent.GetType() == typeof(BlockReference))
                                {
                                    BlockReference blockRef = ent as BlockReference;
                                    if (blockRef.Handle.Value.CompareTo(bHandle.Value) == 0)
                                    {
                                        AttributeCollection attCol = blockRef.AttributeCollection;

                                        foreach (ObjectId att in attCol)
                                        {
                                            using (AttributeReference attRef = trans.GetObject(att, OpenMode.ForRead) as AttributeReference)
                                            {
                                                if (DT.Columns.Contains(blockName + "-" + bHandle.Value + "-" + attRef.Tag))
                                                {
                                                    DR[blockName + "-" + bHandle.Value + "-" + attRef.Tag] = attRef.TextString;
                                                    index++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Spreadsheet.ItemsSource = null;
            Spreadsheet.ItemsSource = DT.DefaultView;
        }
Exemplo n.º 9
0
 public static void EraseBolckTableRecord(this BlockTableRecord btr)
 {
     Tools.StartTransaction(() =>
     {
         if (btr.Id != ObjectId.Null)
         {
             btr = btr.Id.GetObjectForRead <BlockTableRecord>(false);
             if (!btr.IsErased)
             {
                 btr.UpgradeOpen();
                 using (BlockTableRecordEnumerator enumerator = btr.GetEnumerator())
                 {
                     while (enumerator.MoveNext())
                     {
                         enumerator.Current.GetObject((OpenMode)OpenMode.ForWrite).Erase();
                     }
                 }
                 btr.DowngradeOpen();
             }
         }
     });
 }
Exemplo n.º 10
0
        public static List <PosCopy> ReadAll(PosGrouping grouping, bool skipEmpty)
        {
            List <ObjectId> items = new List <ObjectId>();

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
                using (BlockTableRecordEnumerator it = btr.GetEnumerator())
                {
                    while (it.MoveNext())
                    {
                        if (it.Current.ObjectClass == RXObject.GetClass(typeof(RebarPos)))
                        {
                            items.Add(it.Current);
                        }
                    }
                }
            }

            return(ReadAllInSelection(items, skipEmpty, grouping));
        }
Exemplo n.º 11
0
 private void _eraseBolckTableRecord()
 {
     using (Transaction trans = Tools.StartTransaction())
     {
         if (this.BlockTableRecordId != ObjectId.Null)
         {
             BlockTableRecord btr = (BlockTableRecord)this.BlockTableRecordId.GetObject(OpenMode.ForRead, true, true);
             if (!btr.IsErased)
             {
                 btr.UpgradeOpen();
                 using (BlockTableRecordEnumerator enumerator = btr.GetEnumerator())
                 {
                     while (enumerator.MoveNext())
                     {
                         enumerator.Current.GetObject((OpenMode)OpenMode.ForWrite).Erase();
                     }
                 }
                 trans.Commit();
                 _entities = new List <Entity>();
             }
         }
     }
 }
Exemplo n.º 12
0
        private void ButtonWrite_Click(object sender, RoutedEventArgs e)
        {
            if (Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.Count > 0)
            {
                Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.CurrentDocument.Editor.WriteMessage("Close the open documents:\n");
                foreach (Document doc in Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager)
                {
                    Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.CurrentDocument.Editor.WriteMessage(doc.Name + "\n");
                }
                return;
            }

            foreach (DataRow DR in DT.Rows)
            {
                int      index = 1;
                Database acDb  = new Database(false, true);
                using (acDb)
                {
                    if (File.Exists(DR["Filename"].ToString()))
                    {
                        acDb.ReadDwgFile(DR["Filename"].ToString(), FileShare.ReadWrite, false, "");
                        pathExists = DR["Filename"].ToString();
                    }
                    else
                    {
                        acDb.ReadDwgFile(pathExists, FileShare.ReadWrite, false, "");
                    }

                    using (Transaction trans = acDb.TransactionManager.StartTransaction())
                    {
                        BlockTable                 bt      = (BlockTable)trans.GetObject(acDb.BlockTableId, OpenMode.ForWrite);
                        BlockTableRecord           ms      = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                        BlockTableRecordEnumerator recEnum = ms.GetEnumerator();

                        while (index < DT.Columns.Count - 1)
                        {
                            recEnum.Reset();
                            Handle bHandle   = new Handle(long.Parse(DT.Columns[index].ColumnName.Split('-')[1].ToString()));
                            string blockName = DT.Columns[index].ColumnName.Split('-')[0].ToString();

                            while (recEnum.MoveNext())
                            {
                                Entity ent = (Entity)trans.GetObject(recEnum.Current, OpenMode.ForRead);
                                if (ent.GetType() == typeof(BlockReference))
                                {
                                    BlockReference blockRef = ent as BlockReference;
                                    if (blockRef.Handle.Value.CompareTo(bHandle.Value) == 0)
                                    {
                                        AttributeCollection attCol = blockRef.AttributeCollection;

                                        foreach (ObjectId att in attCol)
                                        {
                                            using (AttributeReference attRef = trans.GetObject(att, OpenMode.ForWrite) as AttributeReference)
                                            {
                                                if (DT.Columns.Contains(blockName + "-" + bHandle.Value + "-" + attRef.Tag))
                                                {
                                                    attRef.TextString = DR[blockName + "-" + bHandle.Value + "-" + attRef.Tag].ToString();
                                                    index++;
                                                }
                                            }
                                        }

                                        break;
                                    }
                                }
                            }
                        }
                        trans.Commit();
                        acDb.SaveAs(DR["Filename"].ToString(), DwgVersion.Current);
                    }
                }
            }
        }
Exemplo n.º 13
0
        public void SPlineToLine()
        {
            int    num;
            int    num4;
            object obj;

            try
            {
IL_01:
                ProjectData.ClearProjectError();
                num = -2;
IL_09:
                int num2 = 2;
                Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument;
IL_16:
                num2 = 3;
                Database database = mdiActiveDocument.Database;
IL_1F:
                num2 = 4;
                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    BlockTable            blockTable = (BlockTable)transaction.GetObject(database.BlockTableId, 1);
                    SymbolTableEnumerator enumerator = blockTable.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        ObjectId                   objectId         = enumerator.Current;
                        BlockTableRecord           blockTableRecord = (BlockTableRecord)transaction.GetObject(objectId, 1);
                        BlockTableRecordEnumerator enumerator2      = blockTableRecord.GetEnumerator();
                        while (enumerator2.MoveNext())
                        {
                            ObjectId objectId2 = enumerator2.Current;
                            Entity   entity    = (Entity)transaction.GetObject(objectId2, 1);
                            if (entity is Spline)
                            {
                                Spline spline = (Spline)entity;
                                Line   e      = new Line(spline.StartPoint, spline.EndPoint);
                                CAD.AddEnt(e);
                                spline.Erase();
                            }
                        }
                        if (enumerator2 != null)
                        {
                            enumerator2.Dispose();
                        }
                    }
                    if (enumerator != null)
                    {
                        enumerator.Dispose();
                    }
                    transaction.Commit();
                }
IL_11B:
                goto IL_187;
IL_11D:
                int num3 = num4 + 1;
                num4     = 0;
                @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num3);
IL_141:
                goto IL_17C;
IL_143:
                num4 = num2;
                if (num <= -2)
                {
                    goto IL_11D;
                }
                @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num);
                IL_159 :;
            }
            catch when(endfilter(obj is Exception & num != 0 & num4 == 0))
            {
                Exception ex = (Exception)obj2;

                goto IL_143;
            }
IL_17C:
            throw ProjectData.CreateProjectError(-2146828237);
IL_187:
            if (num4 != 0)
            {
                ProjectData.ClearProjectError();
            }
        }
Exemplo n.º 14
0
        public void FindAndReplace()
        {
            Document acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; //Valitaan avoinna oleva dokumentti
            Database acCurDb = acDoc.Database;

            PromptKeywordOptions promptKey = new PromptKeywordOptions("\nScope:");

            promptKey.Keywords.Add("Drawing");
            promptKey.Keywords.Add("Selection");

            PromptResult promptRes = acDoc.Editor.GetKeywords(promptKey);

            PromptStringOptions promptString       = new PromptStringOptions("\nReplace:");
            PromptResult        promptStringResult = acDoc.Editor.GetString(promptString);

            string replace = promptStringResult.StringResult;

            promptString       = new PromptStringOptions("\nWith:");
            promptStringResult = acDoc.Editor.GetString(promptString);

            string replaceWith = promptStringResult.StringResult;

            switch (promptRes.StringResult)
            {
            case "Drawing":
                using (Transaction trans = acCurDb.TransactionManager.StartTransaction())
                {
                    BlockTable                 bt      = (BlockTable)trans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                    BlockTableRecord           ms      = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
                    BlockTableRecordEnumerator recEnum = ms.GetEnumerator();

                    while (recEnum.MoveNext())
                    {
                        Entity ent = (Entity)trans.GetObject(recEnum.Current, OpenMode.ForRead);
                        if (ent.GetType() == typeof(BlockReference))
                        {
                            BlockReference      blockRef = ent as BlockReference;
                            AttributeCollection attCol   = blockRef.AttributeCollection;

                            foreach (ObjectId att in attCol)
                            {
                                using (AttributeReference attRef = trans.GetObject(att, OpenMode.ForWrite) as AttributeReference)
                                {
                                    if (attRef.TextString.Contains(replace))
                                    {
                                        attRef.TextString = attRef.TextString.Replace(replace, replaceWith);
                                    }
                                }
                            }
                        }
                    }
                    trans.Commit();
                }
                break;

            case "Selection":
                PromptSelectionResult selRes = acDoc.Editor.GetSelection();
                if (selRes.Status == PromptStatus.OK)
                {
                    using (Transaction trans = acCurDb.TransactionManager.StartTransaction())
                    {
                        SelectionSet selSet = selRes.Value;
                        if (selSet[0] != null)
                        {
                            for (int i = 0; i < selSet.Count; i++)
                            {
                                Entity acEnt = trans.GetObject(selSet[i].ObjectId, OpenMode.ForRead) as Entity;
                                if (acEnt != null)
                                {
                                    if (acEnt.GetType() != typeof(BlockReference))
                                    {
                                        return;
                                    }

                                    BlockReference      selectedBlock = acEnt as BlockReference;
                                    AttributeCollection attrCol       = selectedBlock.AttributeCollection;

                                    BlockTable blkTable = trans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                                    BlockTableRecord blkRec;
                                    blkRec = trans.GetObject(blkTable[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;


                                    if (attrCol.Count == 0)
                                    {
                                        return;
                                    }
                                    foreach (ObjectId attRefId in attrCol)
                                    {
                                        using (AttributeReference attRef = trans.GetObject(attRefId, OpenMode.ForWrite) as AttributeReference)
                                        {
                                            if (attRef.TextString.Contains(replace))
                                            {
                                                attRef.TextString = attRef.TextString.Replace(replace, replaceWith);
                                            }
                                        }
                                    }
                                    trans.Commit();
                                }
                            }
                        }
                    }
                }
                break;

            default:
                acDoc.Editor.WriteMessage("\nUnknown keyword\n");
                break;
            }
        }