Renaming a Sheet with a Transaction doesn't show up in Undo / Redo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been using a Find & Replace feature for Sheet Names and Sheet Numbers without incident for a while, but I have now included an Append option as well, however this function doesn't always give a "Undo/Redo" option if it is the first function performed on the model. I am in Revit 2019.2.1.
Here is what I use for code in the Find and Replace:
class FindReplaceSheetName : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; Document doc = uiapp.ActiveUIDocument.Document; App.ControlID.doc = doc; int count = 0; Forms.FindReplaceForm fpf = new Forms.FindReplaceForm(); if (fpf.ShowDialog() == DialogResult.OK) { using (Transaction t = new Transaction(doc)) { try { t.Start("Find & Replace Sheet Name"); foreach (Element sheet in Helpers.Collectors.ByCategory(doc, BuiltInCategory.OST_Sheets)) { if (sheet.Name.Contains(App.ControlID.find)) { sheet.Name = sheet.Name.Replace(App.ControlID.find, App.ControlID.replace); count++; } } t.Commit(); MessageBox.Show("Modified " + count + " Sheet Names","Information",MessageBoxButtons.OK,MessageBoxIcon.Information); return Result.Succeeded; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return Result.Failed; } } } else { return Result.Failed; } } }
Here is what I am using for the Append Code:
class SheetNameAppend : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; Document doc = uiapp.ActiveUIDocument.Document; int count = 0; Forms.SheetNameAppendForm fpf = new Forms.SheetNameAppendForm(); if (fpf.ShowDialog() == DialogResult.OK) { using (Transaction t = new Transaction(doc)) { try { t.Start("Append Sheet Name"); foreach (Element sheet in Helpers.Collectors.ByCategory(doc, BuiltInCategory.OST_Sheets)) { if (App.ControlID.prefix == true) { sheet.Name = App.ControlID.append + sheet.Name; } else { sheet.Name = sheet.Name + App.ControlID.append; } count++; } t.Commit(); MessageBox.Show("Modified " + count + " Sheet Names", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return Result.Succeeded; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return Result.Failed; } } } else { return Result.Failed; } } }
Link copied