private void FindReplaceItem(Transaction tr, ObjectId id) { try { foreach (FindReplaceOptions item in options) { string replacedText = string.Empty; if (frText && id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(DBText)))) { // Single line text DBText text = (DBText)tr.GetObject(id, OpenMode.ForRead); if (GetReplacedText(item.Find, item.Replace, text.TextString, out replacedText)) { text.UpgradeOpen(); text.TextString = replacedText; } } else if (frText && id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(MText)))) { // Multiline text MText mtext = (MText)tr.GetObject(id, OpenMode.ForRead); if (GetReplacedText(item.Find, item.Replace, mtext.Contents, out replacedText)) { mtext.UpgradeOpen(); mtext.Contents = replacedText; } } else if (frDimension && id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Dimension)))) { // Dimension text Dimension dimension = (Dimension)tr.GetObject(id, OpenMode.ForRead); if (GetReplacedText(item.Find, item.Replace, dimension.DimensionText, out replacedText)) { dimension.UpgradeOpen(); dimension.DimensionText = replacedText; } } else if (frLeader && id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(MLeader)))) { // Multileader MLeader leader = (MLeader)tr.GetObject(id, OpenMode.ForRead); if (leader.ContentType == ContentType.MTextContent) { if (GetReplacedText(item.Find, item.Replace, leader.MText.Contents, out replacedText)) { leader.UpgradeOpen(); leader.MText.Contents = replacedText; } } } else if (frAttribute && id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(BlockReference)))) { // Block attributes BlockReference blockRef = (BlockReference)tr.GetObject(id, OpenMode.ForRead); foreach (ObjectId attid in blockRef.AttributeCollection) { AttributeReference attRef = (AttributeReference)tr.GetObject(attid, OpenMode.ForRead); if (GetReplacedText(item.Find, item.Replace, attRef.TextString, out replacedText)) { attRef.UpgradeOpen(); attRef.TextString = replacedText; } } } else if (frTable && id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Table)))) { // Table text Table table = (Table)tr.GetObject(id, OpenMode.ForWrite); for (int i = 0; i < table.Rows.Count; i++) { for (int j = 0; j < table.Columns.Count; j++) { if (GetReplacedText(item.Find, item.Replace, table.Cells[i, j].TextString, out replacedText)) { table.Cells[i, j].TextString = replacedText; } } } } } } catch (System.Exception ex) { OnError(ex); } }