Page MenuHome

'bmesh.ops.delete' Default Parameter: 'context='VERTS' not working.
Confirmed, NormalPublicBUG

Description

System Information
Operating system: Windows-10-10.0.17763-SP0 64 Bits
Graphics card: GeForce GTX 970/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 432.00

Blender Version
Broken: version: 2.83 (sub 8), branch: master, commit date: 2020-03-12 00:33, hash: rB8751af6d1902
Worked: Never (2.8+)

Short description of error
When calling 'bpy.ops.delete' without providing a 'context' argument, the method has no effect. The docs state otherwise.
https://docs.blender.org/api/current/bmesh.ops.html#bmesh.ops.delete

Exact steps for others to reproduce the error

  1. Open a new blend file with a cube
  2. Select the cube and enter edit mode
  3. Execute the following script:
import bpy
import bmesh

mesh = bpy.context.edit_object.data
bm = bmesh.from_edit_mesh(mesh)

bm.verts.ensure_lookup_table()
verts = bm.verts[0:3]

bmesh.ops.delete(bm, geom=verts)

# The verts get correctly deleted when providing context argument.
#bmesh.ops.delete(bm, geom=verts, context='VERTS')

bmesh.update_edit_mesh(mesh)

Event Timeline

Richard Antalik (ISS) changed the task status from Needs Triage to Confirmed.Fri, Mar 13, 5:44 PM

It seems that all parameters of type enum or int for bmesh operators always start with the default value 0.
But in this case, the enum starts with the value 1.
This patch allows you to always use the first enum value as the default value (instead of 0):

diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c
index 2ec7e06a264..99db317a351 100644
--- a/source/blender/bmesh/intern/bmesh_operators.c
+++ b/source/blender/bmesh/intern/bmesh_operators.c
@@ -138,6 +138,8 @@ static void bmo_op_slots_init(const BMOSlotType *slot_types, BMOpSlot *slot_args
                  BMO_OP_SLOT_SUBTYPE_INT_ENUM,
                  BMO_OP_SLOT_SUBTYPE_INT_FLAG)) {
           slot->data.enum_data.flags = slot_types[i].enum_flags;
+          /* Set the first value of the enum as the default value. */
+          slot->data.i = slot->data.enum_data.flags[0].value;
         }
       default:
         break;
Jacques Lucke (JacquesLucke) changed the subtype of this task from "Report" to "Bug".Tue, Mar 17, 3:49 PM