'bmesh.ops.delete' Default Parameter: 'context='VERTS' not working. #74720

Closed
opened 2020-03-13 11:13:17 +01:00 by Andreas Erni · 6 comments

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: blender/blender@8751af6d19
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)
**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: `blender/blender@8751af6d19` 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) ```
Author

Added subscriber: @AndreasErni

Added subscriber: @AndreasErni

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Added subscribers: @ideasman42, @mano-wii

Added subscribers: @ideasman42, @mano-wii

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;

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; ```

This issue was referenced by blender/blender@3a5c16f1c9

This issue was referenced by blender/blender@3a5c16f1c981567a800c1094898e892f84d855a0

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Campbell Barton self-assigned this 2020-04-07 15:25:31 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#74720
No description provided.