bugfix/workaround [#25629] Add torus with autmatic edit mode duplicates mesh after >Aling to View.

adding meshes in C does:
 Add Empty Mesh -> Enter Editmode -> Create Mesh

while python does:
 Add Generated Mesh -> Enter Editmode


problem with this is there is no empty undo state for undo-redo to use so it always gave a duplicate mesh on redo-ing.
workaround by adding an empty mesh, do an undo push, and join the generated mesh into the empty one.

this would be fixed if undo stack spanned modes.
This commit is contained in:
Campbell Barton 2011-02-22 02:47:59 +00:00
parent 36618a0996
commit 4b859e91cb
Notes: blender-bot 2023-02-14 09:03:55 +01:00
Referenced by issue #60410, Crash when adjusting torus when edit mode is enabled for new objects
1 changed files with 14 additions and 0 deletions

View File

@ -82,6 +82,19 @@ def object_data_add(context, obdata, operator=None):
obj_new.matrix_world = add_object_align_init(context, operator)
obj_act = scene.objects.active
# XXX
# caused because entering editmodedoes not add a empty undo slot!
if context.user_preferences.edit.use_enter_edit_mode:
if not (obj_act and obj_act.mode == 'EDIT' and obj_act.type == obj_new.type):
_obdata = bpy.data.meshes.new(obdata.name)
obj_act = bpy.data.objects.new(_obdata.name, _obdata)
obj_act.matrix_world = obj_new.matrix_world
scene.objects.link(obj_act)
scene.objects.active = obj_act
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.ed.undo_push(message="Enter Editmode") # need empty undo step
# XXX
if obj_act and obj_act.mode == 'EDIT' and obj_act.type == obj_new.type:
bpy.ops.mesh.select_all(action='DESELECT')
@ -92,6 +105,7 @@ def object_data_add(context, obdata, operator=None):
#scene.objects.active = obj_new
bpy.ops.object.join() # join into the active.
bpy.data.meshes.remove(obdata)
bpy.ops.object.mode_set(mode='EDIT')
else: