bpy.ops.uv.project_from_view

im trying to UV unwrap a plane via python using:
bpy.ops.uv.project_from_view(orthographic=False, correct_aspect=True, clip_to_bounds=False, scale_to_bounds=False)

but everytime i use that function it returns this error:

Traceback (most recent call last):
File “<blender_console>”, line 1, in <module>
File “C:\Users\Elite\BLENDE~1\Blender2\2.56\scripts\modules\bpy\ops.py”, line 179, in call
ret = op_call(self.idname_py(), None, kw)
SystemError: Operator bpy.ops.uv.project_from_view.poll() failed, context is incorrect

why the context is incorrect? i´m doing that on Edit Mode…
My mouse need´s to be in the 3d view so this operator can work?

bye, thanks in advance.

Your wish not yet found
but this worked:


bpy.ops.uv.unwrap() #object in edit mode!

yeah, that´s the weird thing…
I guess “wrong context” means that my mouse needs to be on the 3D view making this operator useless if I trying to acess it via python.

a really late reply, but I try to do the same and get the same error-message. But if I remeber correctly yesterday it worked in another script I wrote. Any news on this?

Like the operator only work in 3dview , press ‘run script’ and in the 3dview select the meshes(only meshes) and press ‘SPACE’ and write ‘Mapping_multiuv’. BLENDER 2.62

import bpy
class ViewOperator(bpy.types.Operator):

bl_idname = “view3d.multimapping”
bl_label = “Mapping_multiuv”

def invoke(self, context, event):
if context.space_data.type == ‘VIEW_3D’:
for sel in bpy.context.selected_objects:
bpy.context.scene.objects.active = bpy.data.objects[sel.name]
bpy.ops.object.editmode_toggle()
bpy.ops.uv.project_from_view(orthographic=False, correct_aspect=True, clip_to_bounds=False, scale_to_bounds=False)
bpy.ops.object.editmode_toggle()

return {‘RUNNING_MODAL’}
else:
self.report({‘WARNING’}, “Active space must be a View3d”)
return {‘CANCELLED’}

bpy.utils.register_class(ViewOperator)

nice workaround. Thank you.

That doesn’t work in 2.64a (wrong context).

See:http://www.blender.org/documentation/blender_python_api_2_64a_release/bpy.ops.html#overriding-context

Thanks, very helpful