Esempio n. 1
0
        public int processObjectId(DB.Transaction tr, DB.ObjectId objId, FindReplacer findReplacer)
        {
            int replaced = 0;
            var ent      = tr.GetObject(objId, DB.OpenMode.ForWrite, false);

            if (ent is DB.Table)
            {
                var tbl = ent as DB.Table;
                if (tbl.NumRows > 0 && tbl.NumColumns > 0)
                {
                    for (var r = 0; r < tbl.NumRows; r++)
                    {
                        for (var c = 0; c < tbl.NumColumns; c++)
                        {
                            var text = tbl.GetTextString(r, c, 0, DB.FormatOption.FormatOptionNone);
                            var textWithoutFormat = tbl.GetTextString(r, c, 0, DB.FormatOption.IgnoreMtextFormat);
                            if (findReplacer.ContainsIn(text, textWithoutFormat))
                            {
                                tbl.SetTextString(r, c, text.Replace(findReplacer.Find, findReplacer.Replace));
                                replaced++;
                            }
                        }
                    }
                }
            }
            else if (ent is DB.MText)
            {
                var mtext             = ent as DB.MText;
                var text              = mtext.Contents;
                var textWithoutFormat = mtext.Text;
                if (findReplacer.ContainsIn(text, textWithoutFormat))
                {
                    mtext.Contents = text.Replace(findReplacer.Find, findReplacer.Replace);
                    replaced++;
                }
            }
            else if (ent is DB.DBText)
            {
                var dbtext = ent as DB.DBText;
                var text   = dbtext.TextString;
                if (findReplacer.ContainsIn(text, text))
                {
                    dbtext.TextString = text.Replace(findReplacer.Find, findReplacer.Replace);
                    replaced++;
                }
            }
            else if (ent is DB.BlockReference)
            {
                var br   = ent as DB.BlockReference;
                var brId = br.IsDynamicBlock ? br.DynamicBlockTableRecord : br.BlockTableRecord;
                var btr  = (DB.BlockTableRecord)tr.GetObject(brId, DB.OpenMode.ForRead, false);
                foreach (DB.ObjectId objId2 in btr)
                {
                    processObjectId(tr, objId2, findReplacer);
                }
            }

            return(replaced);
        }