Message 1 of 14
Rename Material

Not applicable
07-16-2013
07:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to rename materials, removing unwanted characters. Here is what I have...
FilteredElementCollector materials = new FilteredElementCollector(doc).OfClass(typeof(Material)); Transaction trans = new Transaction(doc); trans.Start(); foreach (Material mat in materials) { if (mat.Name.Contains(".") || mat.Name.Contains("_") || mat.Name.Contains("/") || mat.Name.Contains("\\") || mat.Name.Contains(",")) { StringBuilder sb = new StringBuilder(mat.Name); sb.Replace("_", "-"); sb.Replace(".", "-"); sb.Replace(",", "-"); sb.Replace("/", "-"); sb.Replace("\\", "-"); mat.Name = sb.ToString(); } } trans.Commit();
this works when testing by sending the original name then the revised name to a text box. But does not work for actually renaming the materials. What am I missing? Thanks.