Preventing blender name indexing
<p>I'm using a python script to import and export wavefront obj files in Blender. The problem is that Blender adds an index to an object's name if an object with the same name was already added. For example <code>myObject</code> becomes <code>myObject.001</code> if there was already an object called <code>myObject</code> added in the past (even if said object was removed). When I export the object as .obj the names are no longer the same as before.</p>

<p>How do I reset that "name-counter"?  </p>

<p>Each item in blender must have a unique name within the list of items it belongs to (each name is a dictionary key) and will make a name unique by appending a numeric suffix based on the other items within the file, note that it is based on the file - not the scene, as a blend file can contain multiple scenes. Objects that have been deleted are not considered in this process, while other items like materials and mesh data remain in the lists until the file is closed.</p>

<p>The obj importer first creates the mesh datablock and then creates an object using the same name as the mesh data - this leads to the new objects always having a numeric suffix larger than previous objects.</p>

<p>If you are importing multiple objects using a python script you can rename the object after you import it.</p>

<pre><code>bpy.ops.import_scene.obj(filepath='Object1.obj')
bpy.context.selected_objects[0].name = 'Object'
bpy.context.selected_objects[0].data.name = 'Object'
</code></pre>

<p>In this scenario any existing object with the name "Object" will get renamed to have a suffix.</p>

python blender