I'm trying to override the context, in order to run this Delaunay Triangulation add-on. I'm using the approach suggested in this answer:

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        override = bpy.context.copy()
        override['area'] = area

However the add-on still fails when it tries to create a mesh, due to incorrect context:

Error: Traceback (most recent call last):
  File    "/Applications/Blender/blender.app/Contents/Resources/2.74/scripts/addons/delaunay_voronoi/delaunayVoronoiBlender.py", line 97, in execute
    bpy.ops.view3d.snap_cursor_to_selected()#move 3d-cursor
  File "/Applications/Blender/blender.app/Contents/MacOS/../Resources/2.74/scripts/modules/bpy/ops.py", line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.view3d.snap_cursor_to_selected.poll() failed, context is incorrect

The same error message appears four or five times, but always relating to line 97 of the add-on's script (bpy.ops.view3d.snap_cursor_to_selected()).

Am I overriding the context correctly? Is there anything else I could try?


The simplest remedy is to make the script not depend on the 3d cursor at all. The add-on in this case seems to use the 3d cursor somewhat arbitrarily to store the location of the selected object.

# replace these two lines
bpy.ops.view3d.snap_cursor_to_selected() # move 3d-cursor
tinObj.location = bpy.context.scene.cursor_location #position object at 3d-cursor

# with this line
tinObj.location = obj.location.copy()

it will do the triangulation as desired.

>>> bpy.ops.delaunay.triangulation()
0 duplicates points ignored
0 z colinear points excluded
Triangulate 6 points...
4 triangles
Create mesh...
Info: Mesh created (4 triangles)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.