stupid python question

Hi!
Why this command raises en error in Blender?

bpy.ops.view3d.enable_manipulator(translate = False)

The error:

Traceback (most recent call last):  File "<blender_console>", line 1, in <module>
  File "C:\Program Files\Blender Foundation\Blender\2.70\scripts\modules\bpy\ops.py", line 188, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.view3d.move.poll() failed, context is incorrect

Hi !

That’s a common problem with scripting : operators only work in a specific context. For the enable_manipulator one, it only works if called in the 3D view. But when you’re executing a script in the console or in the text editor, the context is respectively the console view and the text editor view, which are not correct for the enable_manipulator operator, hence the error (The reason is that you can disable a manipulator in one 3D view while keeping it in another, so it can’t be a “software-wide” operation).
I think there is a way to build manually a valid context from scratch but I don’t know how.

You can set the property without operator, but need to find the correct spaces (3D View) either way:

import bpy

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        # any combination of the 3 shown set elements, from 0 to 3!
        area.spaces[0].transform_manipulators = {'TRANSLATE', 'ROTATE', 'SCALE'}

        # Or disable the manipulator widget:
        #area.spaces[0].show_manipulator = False

Ok I got it…I have to say that this is really really uncomfortable! All evening I was digging python in Blender and I couldn’t script a damn thing. Is there any chance that one day Blender scripting will act more like python in Maya or XSI?
Kevar, CoDemanX thanks a lot! You made my day!