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; } } }
Dear Sean,
Thank you for your report.
I can happily pass it on to the development team for you for analysis.
However, they require a complete minimal reproducible case to be able to debug the issue:
https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b
Can you provide that, please?
Thank you!
Best regards,
Jeremy
Thanks Jeremy,
Prepping to submit the files as requested, I have noticed that my results are not reproducible on every occasion and may be pointing to our template file as both a new Imperial project as well as the Autodesk Architectural Sample model do not act the same way, yet any model based on our template does, which I am not able to share in its entirety. I will continue to chase this, but for not it appears to be model specific for some reason.
Hi,
I have an addin that has the same unod/redo issue but I noticed the undo button is greyed out when I manually rename Sheets in Workshared models (either on local drive or BIM360).
I found another related post: https://forums.autodesk.com/t5/revit-api-forum/transactions-not-reliably-showing-up-in-revit-undo/m-...
I'm having this problem as well. I'm trying to set up a script to find/replace a string in the electrical equipment names. The script was working smoothly, replacing the string in the equipment, and in the circuit. As soon as I added functionality to replace the string in the Panel Schedule title, the undo button stopped working. I'm using Revit 2021.1.
schedule.get_Parameter(DB.BuiltInParameter.PANEL_SCHEDULE_NAME).Set(new_schedule_name)
Same issue renaming Schedules and Panel Schedules using the API in Revit 2022.1.
The enclosing transaction does not show in the Undo panel.
Has anyone gotten this figured out?
The only semi-conclusion I came too was that it was trying to do it as the first action on the model when I was testing. If I did just a out anything "manually" first then it would show. Not sure why, but almost like the undo list need initialized in some way.
That did not work for me.
In fact, it revealed an even worse issue!
Renaming schedules in a transaction is clearing out the Undo list as if I've just opened the file!
Here is my test Macro function, I am selecting a bunch of schedules in the Project Browser before I launch the macro:
public void TestScheduleRename()
{
var sel = this.ActiveUIDocument.Selection.GetElementIds();
using( var t = new Transaction( this.ActiveUIDocument.Document, "Rename Schedules")){
t.Start();
var count = 0;
foreach(var id in sel)
{
ViewSchedule e = this.ActiveUIDocument.Document.GetElement(id) as ViewSchedule;
if (e == null) continue;
e.Name = "Sch" + count.ToString();
count ++;
}
t.Commit();
}
}
Update I:
I tried the macro on a vanilla file created from the Arch Imperial template both in none-workshared and workshared scenarios, and it worked (an undo entry was created for the transaction and the undo history was preserved)
The model I was testing on initially was a detached copy of a BIM360 model. I will try to create a BIM360 test project with the vanilla file and see if that still works.
Update II:
I ran some more tests on a new file using the Imperial Construction template in Revit 2022.
I didn't have to upload it to BIM360 to reproduce the issue.
Conclusion: In a workshared file, the undo history will intermittently be cleared when I execute the above macro, and even when I perform some actions in the Project Browser (deleting a view for example).
To Reproduce (see the attached screen recording for reference):
Tested in Revit 2022 and 2020, not sure how far back this goes.
A central copy of the test file with the embedded macro is attached.
Thank you very much for testing and your report. I'll keep a lookout for your update, in case you discover an unexplainable and unexpected problem that needs passing on to the development team...
Dear Sam, Perry and Sean,
Thank you for very much your report and all your research on this. Sorry to hear about these issues and that you have been struggling with them for so long.
I logged the issue REVIT-211051 [API Renaming a Sheet or panel schedule corrupts undo history] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.
You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.
This issue is important to me. What can I do to help?
This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:
This information is crucial. Our engineering team has limited resources and must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.
Best regards,
Jeremy
Thanks for the update @jeremy_tammik , and although I have not verified it, I believe I have seen a note that either in the latest R23 or R24 that the issues of sheet renaming and the browser updated was addressed. So, this may be a legacy issue and moot going forward.
Oh wow. Thank you for pointing that out. Let's hope it is already resolved, then. Any chance you could find the note you are thinking of?
Well, it would seem that I may have gotten my topics crossed. We had another very similar that discussed the browser updating when sheets were renamed and that is what I was thinking of.
https://help.autodesk.com/view/RVT/2023/ENU/?guid=RevitReleaseNotes_2023updates_2023_1_Resolved_Issu...
And unfortunately, I just testing this in R24 (same process as it was in my initial post R19) and it still does the same thing. If the very first command is renaming (prefixing) a bunch of sheets, that does not show up in the Undo list.
"TESTING" was added to these sheets, and you can see the Undo list is not active.
Any chance you could try to rename each sheet with a separate transaction, and assimilate them all in a transactionGroup? Not sure that would help, but it would at least be something different to try.
Can't find what you're looking for? Ask the community or share your knowledge.