Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

I want to rename a large number of items. Doing so manually could take quite some time. I want to use python to rename the object. To find out the python command for renaming I renamed an object manually and looked in the console for the echoed command. The command was:

bpy.ops.object.select_all(action='TOGGLE')

This command does not seem to be the correct command for renaming. It does not even contain the new name in the command. I also tried to look up the python command reference for the name, but the link was a dead end.

How can I rename an object using python?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You can access them by iterating and assign the name property:

import bpy

for obj in bpy.context.selected_objects:
    obj.name = "newName"

Blender automatically add .001, .002 and so on to newName if another datablock of same type and name already exists. You may need to check a name pattern within the for-loop.

Another example - rename all Mesh objects in current scene that start with C (e.g. Cube, case insensitive):

for obj in bpy.context.scene.objects:
    if obj.type == 'MESH' and obj.name.lower().startswith("c")
        obj.name = "newName"
share|improve this answer
    
could you add the command for the selected objects? –  Vader Feb 28 at 19:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.