# Naming object issues

I'm trying to add some items to the scene and rename them but ran into some issues. Example code:

import bpy
context = bpy.context
name = "Cube"

item = context.active_object
item.name = name

item = context.active_object
item.name = name


I thought that this code would name the first cube to "Cube" and the second cube to Cube.001, but it actually does the opposite and I end up with the second cube (10,20,30) named Cube and the first is named Cube.001. Is this a bug?

Is there anyway around this other than manually looping over existing objects and generating a unique name?

I would be happy to use bmesh instead (as that will give me the expected behaviour), but I can't get that method to work either as I need to create a uv map as well. Example workaround:

import bpy
import bmesh

bm = bmesh.new()
bmesh.ops.create_cube(bm, size=1.0, calc_uvs=True)
mesh_name = "Cube"
mesh_data = bpy.data.meshes.new(mesh_name)
bm.to_mesh(mesh_data)
bm.free()

mesh_obj = bpy.data.objects.new(mesh_data.name, mesh_data)

• No.  bpy.data.objects["name"]is a map/dictionary. And you can test using "bpy.data.objects.get("name") Sep 29, 2020 at 14:43