It was indeed useful; I can't imagine what I had been doing previously. Given that I was awarded the solution, and it seems one cannot be stripped of an award, and in the spirit of completeness, the following is the finished code based on your macro. Thanks, and you should have this one. Dale
public void RenameLineStyles(RvtDoc pDoc, string pstrFind, string pstrReplace, bool pblnMatchCase)
{
Category linesCat = pDoc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
IList<Category> catList;
using (Transaction tr = new Transaction(pDoc, "Rename Linestyle"))
{
tr.Start();
if (pblnMatchCase)
{
catList = linesCat.SubCategories.Cast<Category>().Where(c => c.Name.ToUpper().Contains(pstrFind.ToUpper())).ToList();
}
else
{
catList = linesCat.SubCategories.Cast<Category>().Where(c => c.Name.Contains(pstrFind)).ToList();
}
foreach (Category cat in catList)
{
ElementId eid = cat.Id as ElementId;
Element type = pDoc.GetElement(eid);
if (null != type)
{
type.Name = Rename(cat.Name, pstrFind, pstrReplace);
}
}
tr.Commit();
}
}
public static string Rename(string pstrOldName, string pstrFind, string pstrReplace)
{
StringBuilder sbNewName = new StringBuilder(pstrOldName);
sbNewName.Replace(pstrFind, pstrReplace);
return sbNewName.ToString();
}
One disclaimer, my actual usage is a little different so this exact code has not been tested. Nevertheless, it should be ok. Hopefully someone finds it useful one day.
______________
Yes, I'm Satoshi.