0

I have a bare bones script that has 2 lines:

import bpy

bpy.ops.mesh.rip()

I've made sure I am in EDIT mode and have edges selected in edge mode. It fails with

RuntimeError: Operator bpy.ops.mesh.rip.poll() failed, context is incorrect

But I've fulfilled all of the context rules in the docs. Anybody?

Sudo
  • 15
  • 3

2 Answers2

1

For whatever reason, I couldn't get ANY Blender bpy.ops.mesh.rip rip_move rip_edge rip_edge_move at all BUT the same thing exists in bmesh functionality called split_edges (facepalm). Following code splits all edges along any edge that is marked as "seam".

bm = bmesh.new()
bm.from_mesh(me)

seamEdges = []
for edge in bm.edges:
    if edge.seam:
        edge.select = True
        seamEdges.append(edge)

bmesh.ops.split_edges(bm,edges=seamEdges)
#apply
bpy.ops.object.mode_set(mode = 'OBJECT')
bm.to_mesh(me)
bm.free()
Sudo
  • 15
  • 3
  • Cool. Recommend using bmesh over bpy.ops.mesh whenever possible. List comp is handy here edges=[e for e in bm.edges if e.seam] – batFINGER Dec 14 '19 at 03:05
0

Found this Older Thread that helped me. Essentially, I've ignored everything but this part: bpy.ops.mesh.rip('INVOKE_DEFAULT'), and it started working. Not sure how or why it works, since I haven't found the INVOKE_DEFAULT part in API docs, nor in blender source code for blender/source/blender/editors/mesh/editmesh_rip.c. I'm using Blender 2.90.1.

  • `'INVOKE_DEFAULT`` is an execution context. An operator has an invoke method. If it is called via UI, by default the operator is "invoked" in this execution context with default settings, unless set to do otherwise. See https://blender.stackexchange.com/questions/6101/poll-failed-context-incorrect-example-bpy-ops-view3d-background-image-add/6105#6105 – batFINGER Feb 05 '21 at 09:29