collection iteration and renaming, output unpredictable results #107027
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
5 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#107027
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: Linux-5.19.0-38-generic-x86_64-with-glibc2.35 64 Bits
Graphics card: NVIDIA GeForce RTX 3080 Laptop GPU/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 515.105.01
Blender Version
Broken: version: 3.4.1, branch: blender-v3.4-release, commit date: 2022-12-19 17:00, hash:
rB55485cb379f7
Worked: (newest version of Blender that worked as expected)
Short description of error
[Please fill out a short description of the error here]
collection iteration and renaming, output unpredictable results
please run the script with attached file and check the results.
this script suppose to rename all object with lower case and prefix.
unfortunately, after running the script on N number of objects the results are unpredictable
Hi @barakooda , there's a name length limit to all ID data blocks (64 characters). That's why when your prefix gets too long, they will get truncated (if that's what you are referring to as "unpredictable").
Hi @ChengduLittleA
no just run the code and check this image for reference:
do you see the unwanted repeating ?
@barakooda Looks that's what exactly what your script does?
@ChengduLittleA
no,
the script adds the prefix only a single time.
Hi @barakooda , I can confirm that's indeed what's happening. I think I know the reason why the script is doing it in such a way. When you change the name of an object, blender will sort the object list, so
bpy.data.objects
would change. By naming stuff this way, you will potentially iterate over the same object because the list order changed.Instead, you could use
for ob in bpy.data.objects.values()
, this way it preserves the list order and you only iterate over objects once.This is sort of touched by https://docs.blender.org/api/3.6/info_gotcha.html
Closest to it is here:
This could be more explicit, but I do think this is the same ballpark.
@ideasman42 , @sergey : would you agree?
Indeed. Maybe can have a bullet point of common cases (without giving full-blown code snippet) ?
Noted in docs, closing.