i want to know how to create adaptive suffix, that are "content aware" of the situation, to avoid erasing object that have the same names. i think that this is a classic use of python, could someone explain or give me a link to a explanation/ tutorial that can help me understand how this adaptive renaming system work ?
for example in this code below im automatically creating a save as copy in the directory file.
import bpy import os try: os.mkdir(os.path.dirname(bpy.data.filepath)+"\\save as copy\\") except: print('directory already created') Dir = os.path.dirname(bpy.data.filepath) + "\\save as copy\\" bpy.ops.wm.save_as_mainfile(copy=True, filepath= Dir +"Copy.blend")
the only problem is that it erase the previous .blend everytime i do the action, id much prefer to implement an adaptive suffix, that create "copy 001" if copy already exist; "copy 002" if 001 already exist... i could do that with condition but i dont know how to reproduce the steps indefinitely.
in a precedent code someone show me a way to do this ? i dont know if its specific to the situation or not, but i didnt understand how to reproduce thoses act for my situation:
import bpy context = bpy.context scene = context.scene A = context.object i = 1 pref = "%s Mirror " % A.name name = "%s%d" % (pref, i) while A.modifiers.get(name): i += 1 name = "%s%d" % (pref, i) bpy.ops.object.modifier_add(type='MIRROR') A.modifiers[len(A.modifiers)-1].name = name bpy.ops.object.empty_add(type='CUBE') bpy.ops.transform.resize(value=(0.01, 1, 1), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='ENABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.00439353) E = bpy.context.selected_objects E.name = name A.modifiers[name].mirror_object = E A.select_set(state=True)
import bpy i = 1 pref = "neww" name = "%s%d" % (pref, i) while bpy.context.object.name.get(name): i += 1 name = "%s%d" % (pref, i) for ob in bpy.context.selected_objects: ob.name = name
i also tried
import bpy i = 1 pref = "new" name = "%s%d" % (pref, i) while ob.name = name i += 1 name = "%s%d" % (pref, i) for ob in bpy.context.selected_objects: ob.name = name