When loading old files, it's possible the names aren't utf-8 compliant. Meaning Python won't be able to modify them. See: T23197
Besides using a hex editor, is there a way to fix names from very old blend files so they are utf-8 compliant?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
It's possible to get strings in Python as bytes, which allows to re-encode them into utf-8:
import bpy for m in bpy.data.materials: name_as_bytes = m.path_resolve("name", False).as_bytes() name_as_utf8 = name_as_bytes.decode('utf8', 'surrogateescape') m.name = name_as_utf8
To run this on your entire file:
import bpy def id_iter(): type_iter = type(bpy.data.objects) for attr in dir(bpy.data): data_iter = getattr(bpy.data, attr, None) if type(data_iter) == type_iter: for id_data in data_iter: if id_data.library is None: yield id_data def wash_name(id_data) name_as_bytes = id_data.path_resolve("name", False).as_bytes() name_as_utf8 = name_as_bytes.decode('utf8', 'surrogateescape') id_data.name = name_as_utf8 for id_data in id_iter(): wash_name(id_data)
Ideally loading old files will always work. In this case it's not done because its a big change for a relatively rare problem.