Renaming an ID through RNA does not consistently increment OTHER or CURRENT ID in case of name collision #71244

Closed
opened 2019-10-31 15:07:39 +01:00 by Yannick Castaing · 14 comments

Renaming an ID through RNA does not consistently increment either the current ID or the other ID in case of name collision. This depends on the existing order of the data-blocks before the rename happens.

As pointed out in the comment below by @ideasman42, fixing this in one way or the other is trivial. But we have to choose one of the two solutions:

  • Add incremented number suffix to renamed ID (this seems to be the soundest solution, as it will ensure we never silently rename a random other ID).
  • Add incremented number suffix to the other ID.

Note that it should also be ensured that behavior is consistent with Outliner renaming code as well.


Original Report

System Information
Operating system: Windows-10-10.0.17134 64 Bits
Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 431.60

Blender Version
Broken: version: 2.80 (sub 75), branch: master, commit date: 2019-07-29 14:47, hash: f6cb5f5449
Worked: (optional)

Short description of error
when we try to rename an object with an already used name,, it will rename the existing occurence, not the incoming one

Exact steps for others to reproduce the error
works with the default scene (with Cube, Light, Camera) :

  • take the Cube, x2 clic on the name, rename it in "Camera". Enter
  • the original Camera (previously named "Camera") will be renamed in "Camera.001" and the Cube will be renamed in "Camera"

I gess it should be the opposite : the incoming similar name is incremented, but the original name stays the same

Renaming an ID through RNA does not consistently increment either the current ID or the other ID in case of name collision. This depends on the existing order of the data-blocks before the rename happens. As pointed out in the comment below by @ideasman42, fixing this in one way or the other is trivial. But we have to choose one of the two solutions: * Add incremented number suffix to renamed ID (this seems to be the soundest solution, as it will ensure we never silently rename a random other ID). * Add incremented number suffix to the other ID. Note that it should also be ensured that behavior is consistent with Outliner renaming code as well. ------------ Original Report ----------------- **System Information** Operating system: Windows-10-10.0.17134 64 Bits Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 431.60 **Blender Version** Broken: version: 2.80 (sub 75), branch: master, commit date: 2019-07-29 14:47, hash: `f6cb5f5449` Worked: (optional) **Short description of error** when we try to rename an object with an already used name,, it will rename the existing occurence, not the incoming one **Exact steps for others to reproduce the error** works with the default scene (with Cube, Light, Camera) : - take the Cube, x2 clic on the name, rename it in "Camera". Enter - the original Camera (previously named "Camera") will be renamed in "Camera.001" and the Cube will be renamed in "Camera" I gess it should be the opposite : the incoming similar name is incremented, but the original name stays the same

Added subscriber: @BoUBoU

Added subscriber: @BoUBoU

#90052 was marked as duplicate of this issue

#90052 was marked as duplicate of this issue

Added subscriber: @ideasman42

Added subscriber: @ideasman42

This has come up before.

Internal detail: which data-block gets numbered depends on the current order, So if you first rename the cube to A, then rename to Camera, this wont happen.

We can change this so the item you're renaming always gets numbered and you never accidentally rename other items.

diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 49fdf9c67d5..6bc79c3baa9 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -145,7 +145,7 @@ void rna_ID_name_set(PointerRNA *ptr, const char *value)
   ID *id = (ID *)ptr->data;
   BLI_strncpy_utf8(id->name + 2, value, sizeof(id->name) - 2);
   BLI_assert(BKE_id_is_in_global_main(id));
-  BLI_libblock_ensure_unique_name(G_MAIN, id->name);
+  BKE_libblock_rename(G_MAIN, id, value);
 
   if (GS(id->name) == ID_OB) {
     Object *ob = (Object *)id;

However sometimes users want this behavior, having to find the item and rename it so this one can take it's place (while arguably correct) is tedious.

This is more a design task though, how it works isn't great but isn't a mistake in the code.

This has come up before. **Internal detail:** which data-block gets numbered depends on the current order, So if you first rename the cube to `A`, then rename to `Camera`, this wont happen. We can change this so the item you're renaming always gets numbered and you never accidentally rename other items. ``` diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 49fdf9c67d5..6bc79c3baa9 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -145,7 +145,7 @@ void rna_ID_name_set(PointerRNA *ptr, const char *value) ID *id = (ID *)ptr->data; BLI_strncpy_utf8(id->name + 2, value, sizeof(id->name) - 2); BLI_assert(BKE_id_is_in_global_main(id)); - BLI_libblock_ensure_unique_name(G_MAIN, id->name); + BKE_libblock_rename(G_MAIN, id, value); if (GS(id->name) == ID_OB) { Object *ob = (Object *)id; ``` However sometimes users want this behavior, having to find the item and rename it so this one can take it's place (while arguably *correct*) is tedious. This is more a design task though, how it works isn't great but isn't a mistake in the code.
Bastien Montagne changed title from Automatic renaming increment the existing name, and not the incoming one to Renaming an ID through RNA does not consistantly increment OTHER or CURRENT ID in case of name collision 2019-12-18 16:36:30 +01:00

Added subscriber: @mont29

Added subscriber: @mont29
Bastien Montagne changed title from Renaming an ID through RNA does not consistantly increment OTHER or CURRENT ID in case of name collision to Renaming an ID through RNA does not consistently increment OTHER or CURRENT ID in case of name collision 2019-12-18 16:41:12 +01:00

I would also rather just increment current ID's name, instead of changing some random other ID's name…

We could also add an operator to allow the other behavior (i.e. always set affected ID to exactly given name, and rename the other in case of name collision)?

I would also rather just increment current ID's name, instead of changing some random other ID's name… We could also add an operator to allow the other behavior (i.e. always set affected ID to exactly given name, and rename the other in case of name collision)?

@mont29 while incrementing the current ID is the correct solution - I suspect some users will run into situations where they don't know or care what the other ID is called and want to take it's name.
Did you have an idea how this operator would be accessed?

I was thinking we could...

  • Always increment the current ID (as you suggest).
  • Have an exception for the UI, which detects the case where the name started out with a number and the only edit was to remove this number. In this case rename the other data-block.

This way only intentional removal of the extension renames the other data & only from the UI.

The Python API could have a function for this if it's needed.

@mont29 while incrementing the current ID is the correct solution - I suspect some users will run into situations where they don't know or care what the other ID is called and want to take it's name. Did you have an idea how this operator would be accessed? I was thinking we could... - Always increment the current ID *(as you suggest)*. - Have an exception for the UI, which detects the case where the name started out with a number and the only edit was to remove this number. In this case rename the other data-block. This way only intentional removal of the extension renames the other data & only from the UI. The Python API could have a function for this if it's needed.

Added subscribers: @WilliamReynish, @pablovazquez

Added subscribers: @WilliamReynish, @pablovazquez

@ideasman42 I don’t have a very strong opinion, but even for UI, I would not try to be smart… even though I can see how much more friendly/handy that behavior would be, compared to having to call some 'force rename' operator, this would introduce a weird special behavior which might backfire in some cases as well.

Note that we want to add a 'contextual' menu to ID template, since we are adding more and more operations there and we cannot keep adding buttons and/or weird 'Shift-click' thingies. So exposing that would be a natural place for that 'force rename' operator I guess? We could also add some 'Shift-click' on the name field to trigger 'force rename' behavior I guess…

Think we could use the #user_interface team advice here as well, @pablovazquez ? @WilliamReynish ?

@ideasman42 I don’t have a very strong opinion, but even for UI, I would not try to be smart… even though I can see how much more friendly/handy that behavior would be, compared to having to call some 'force rename' operator, this would introduce a weird special behavior which might backfire in some cases as well. Note that we want to add a 'contextual' menu to ID template, since we are adding more and more operations there and we cannot keep adding buttons and/or weird 'Shift-click' thingies. So exposing that would be a natural place for that 'force rename' operator I guess? We could also add some 'Shift-click' on the name field to trigger 'force rename' behavior I guess… Think we could use the #user_interface team advice here as well, @pablovazquez ? @WilliamReynish ?

Added subscriber: @c2ba

Added subscriber: @c2ba

Added subscriber: @kioku

Added subscriber: @kioku

As I have run into this recently - this behaviour should change. Hidden renaming of things is really bad - especially if you setup names carefully for further processing.

Guess a 'force' flag in the F2 rename would be fine tho.

As I have run into this recently - this behaviour should change. Hidden renaming of things is really bad - especially if you setup names carefully for further processing. Guess a 'force' flag in the F2 rename would be fine tho.
Added subscribers: @marty3000, @PratikPB2123, @lichtwerk, @kursadk
Philipp Oeser removed the
Interest
Core
label 2023-02-09 14:43:17 +01:00

Reported again in #115192 / !116246, was agreed to go for 'always rename newly-named data' behavior for the time being. Committed as 195bb4f8f5 .

The opposite behavior (rename existing data) can be implemented separately for the UI renaming aspect.

Think we can close this task too now.

Reported again in #115192 / !116246, was agreed to go for 'always rename newly-named data' behavior for the time being. Committed as 195bb4f8f5 . The opposite behavior (rename existing data) can be implemented separately for the UI renaming aspect. Think we can close this task too now.
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2024-01-15 12:51:16 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#71244
No description provided.