Allow name-swapping when renaming IDs from the UI after 4.1

After 4.1 when you set name of object A to “Cube” and “Cube” is already present as object B it will rename object A to “Cube.001”.
Prior to 4.1 it would change A → “Cube” and B → “Cube.001”. Which seems more intuitive though it’s a bit bad practive given that it renamed object B though it never asked to do so (atleast explicitly).

Explained here:

Any thought how name-swapping can be allowed after 4.1 using an addon?

Had an idea that it can be possible using bpy.msgbus.subscribe_rna to object’s (or other IDs) names but it has some problems:

  1. need to somehow ensure that there will be a subscription to all objects/IDs. And the only way to do in Python API rn is to ensure it in depsgraph_update_post which seems to be overkill - iterating over all IDs at every despgraph update won’t be good for performance.

  2. even after renaming A → “Cube” callback from bpy.msgbus.subscribe_rna gets called already after A name is changed to “Cube.001”. So there is no way to know whether usually actually changed it to “Cube.001” or they intended to rename it to “Cube”. Resolving that again would take storing all previous object names in depsgraph_update_post

Alternatively, there could be a button in object’s context menu that would use a different type of renaming that would allow name-swap. The downsides:

  1. user would have to use this button only for renaming as renaming by just clicking on object’s name from outliner will result in renaming without name-swap, which is kind of unintuitive but could be good enough

  2. won’t work for other IDs (materials, etc) as you typically change their names directly, not through context menus.

1 Like

Okay, I’ve released a small addon that does just that - returns old renaming behaviour adding on F2 hotkey - Return Old Renaming Objects Behaviour in Blender 4.1+ - Blender Market

Technically speaking, I’ve just added new operator that adds a custom popup for renaming objects (and other IDs). Using bpy.msgbus.subscribe_rna didn’t worked out as it indeed requires a caching of all available IDs names which is overkill and couldn’t find other way to make the old renaming work when you double-click object’s name in outliner.

To solve renaming for other elements (like materials and meshes) I just utilize the current context, I’ve changed F2 button behaviour when it’s called from material properties - now it’s trying to rename an active material (same for meshes), effectively allowing to name swapping rename for materials and meshes without going to outliner.

2 Likes