Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Renaming a Sheet with a Transaction doesn't show up in Undo / Redo

16 REPLIES 16
Reply
Message 1 of 17
Sean_Page
1169 Views, 16 Replies

Renaming a Sheet with a Transaction doesn't show up in Undo / Redo

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;
            }
        }
    }

 

 

16 REPLIES 16
Message 2 of 17
jeremytammik
in reply to: Sean_Page

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

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 17
Sean_Page
in reply to: jeremytammik

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.

Message 4 of 17

UndoRedo.gif

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-...

Message 5 of 17

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)
Message 6 of 17
sam.najjarJVR3P
in reply to: Sean_Page

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?

Message 7 of 17
Sean_Page
in reply to: Sean_Page

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.

Message 8 of 17
sam.najjarJVR3P
in reply to: Sean_Page

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):

  1. Create a new file from the Imperial Construction Template.
  2. Make it workshared.
  3. Save as central and Close.
  4. Reopen the central file.
  5. Save and Close.
  6. Reopen the central file.
  7. Draw some walls to initialize the Undo history.
  8. Select some schedules in the Project Browser.
  9. Apply the macro (code above).
  10. The Undo history will be cleared. If not, do some more actions in the project browser like deleting the newly renamed schedules and then applying the macro again on others. Sometimes it takes 2 or 3 iterations to see the issue.
  11. Test the same with a local copy of the central.
  12. When I created the local copy for the first time, I couldn't reproduce the issue, but when I closed and created another local overwriting the previous one, the issue happened again.

 

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.

 

Message 9 of 17

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...

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 10 of 17

This is the same error I was (and still am) encountering - any change to
the panel schedule names completely wipes the undo history. Is this a bug?
Message 11 of 17

Thank you for the follow up Jeremy, I've updated my reply above with my new findings. Let me know if more details are required to further investigate the issue.
Message 12 of 17
jeremy_tammik
in reply to: Sean_Page

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:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

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

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 13 of 17
Sean_Page
in reply to: Sean_Page

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.

Message 14 of 17
jeremy_tammik
in reply to: Sean_Page

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?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 15 of 17
Sean_Page
in reply to: Sean_Page

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...

spage_0-1692195159393.png

 

Message 16 of 17
Sean_Page
in reply to: Sean_Page

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.

spage_0-1692195527466.png

 

Message 17 of 17
rhanzlick
in reply to: Sean_Page

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.

Post to forums  

Rail Community


Autodesk Design & Make Report