[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35046] trunk/blender/release/scripts/ modules/add_object_utils.py: bugfix/workaround [#25629] Add torus with autmatic edit mode duplicates mesh after >Aling to View.

Campbell Barton ideasman42 at gmail.com
Tue Feb 22 03:47:59 CET 2011


Revision: 35046
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35046
Author:   campbellbarton
Date:     2011-02-22 02:47:59 +0000 (Tue, 22 Feb 2011)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/add_object_utils.py

Modified: trunk/blender/release/scripts/modules/add_object_utils.py
===================================================================
--- trunk/blender/release/scripts/modules/add_object_utils.py	2011-02-22 02:42:19 UTC (rev 35045)
+++ trunk/blender/release/scripts/modules/add_object_utils.py	2011-02-22 02:47:59 UTC (rev 35046)
@@ -82,6 +82,18 @@
     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)
+            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 +104,7 @@
         #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:




More information about the Bf-blender-cvs mailing list