In this code for 2.8, that works, I am creating a mirror modifier assigned to a cube.
import bpy
OB = bpy.context.selected_objects[0]
bpy.ops.object.modifier_add(type='MIRROR')
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.empty_add(type='CUBE', view_align=False, location=(bpy.context.scene.cursor_location))
OA = bpy.context.selected_objects[0]
bpy.context.object.name = "Mirror Axes"
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)
OB.modifiers["Mirror"].mirror_object = OA
The problem is that I cannot use this script multiple times correctly because of this part:
OB.modifiers["Mirror"].mirror_object = OA
The object will always have a modifier named "Mirror" and if I use this script two times the modifier named "Mirror" will always be the first one and I want it to be the same modifier.
So it needs to be more something like this:
OB = bpy.context.selected_objects[0]
bpy.ops.object.modifier_add(type='MIRROR')
***RENAME MIRROR MODIFIER TO A CUSTOM NAME THAT CHANGE EACH TIME***
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.empty_add(type='CUBE', view_align=False, location=(bpy.context.scene.cursor_location))
OA = bpy.context.selected_objects[0]
bpy.context.object.name = "Mirror Axes"
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)
OB.modifiers["***CUSTOM UNIQUE NAME THAT I JUST CREATED EARLIER***"].mirror_object = OA
---- ---- EDIT AFTER RESPONSE OF MARTINZ --- ---
or like this with this new "if" method that i dont know yet
import bpy
A = bpy.context.selected_objects[0]
if "QuickMirror1" not in A.modifiers:
bpy.ops.object.modifier_add(type='MIRROR')
A.modifiers[len(A.modifiers)-1].name = "QuickMirror1"
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[0]
E.name = "Mirror Axes1"
A.modifiers["QuickMirror1"].mirror_object = E
if "QuickMirror1" in A.modifiers:
if "QuickMirror2" not in A.modifiers:
bpy.ops.object.modifier_add(type='MIRROR')
A.modifiers[len(A.modifiers)-1].name = "QuickMirror2"
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[0]
E.name = "Mirror Axes2"
A.modifiers["QuickMirror2"].mirror_object = E
if "QuickMirror2" in A.modifiers:
if "QuickMirror3" not in A.modifiers:
bpy.ops.object.modifier_add(type='MIRROR')
A.modifiers[len(A.modifiers)-1].name = "QuickMirror3"
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[0]
E.name = "Mirror Axes3"
A.modifiers["QuickMirror3"].mirror_object = E
if "QuickMirror3" in A.modifiers:
if "QuickMirror4" not in A.modifiers:
bpy.ops.object.modifier_add(type='MIRROR')
A.modifiers[len(A.modifiers)-1].name = "QuickMirror4"
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[0]
E.name = "Mirror Axes4"
A.modifiers["QuickMirror4"].mirror_object = E
i got an error message
Converting py args to operator properties: enum "MIRROR" not found in ()
i dont understand him but my code work fine four time in a row... it seams so absurd to me that i need to do this!
there's really no way inside of python to generate a name that change each time and choose the same name inside of the code ????
thanks