Change manipulator mode in 2.5

I wrote a simple script to change the state of the 3d manipulator in Blender 2.5 (to allow all you freaks to make Max/Maya/C4d/etc.-like keybindings of it).

Just copy the following code to a file called manipulator(or anything).py and put it in your .blender/scripts/op/-folder:

import bpy

class ToggleManipulatorMode(bpy.types.Operator):
    '''Changes the maipulator mode'''
    bl_idname = "view3d.manipulator_mode"
    bl_label = "Toggle Manipulator Mode"
    bl_register = False
    bl_undo = False

    tool = bpy.props.IntProperty(name="Tool",default=1,min=1,max=3)
    additive = bpy.props.BoolProperty(name="Additive",default=False)

    def poll(self, context):
        return context.space_data.type == "VIEW_3D"

    def execute(self, context):
        if == False:

        if == 1:
        if == 2:
        if == 3:
        return ('FINISHED',)


if __name__ == "__main__":

Then start blender and run the code below from a text editor. Now if you open the user preferences, select the “View3D”-keymap, press edit and scroll to the bottom you should see three new entries. You can map these to whatever you want (NOTE: for some strange reason you will have to expand the items and select “PRESS” from the menu to the left of the checkboxes foor them to work).

import bpy

kc =[0].active_keyconfig
km = kc.keymaps.get("View3D")
kmi = km.add_item('view3d.manipulator_mode','Q','PRESS') = 1
kmi = km.add_item('view3d.manipulator_mode','W','PRESS') = 2
kmi = km.add_item('view3d.manipulator_mode',"E",'PRESS') = 3

Thank you very much. The operator is great. But this script doesn’t work. Why?

I had to add hotkey manually. Only the Q mode works.

Everything works for me. :confused:

Ive got all the tick(toggle)-boxes ticked(toggled).
maybe that helps…

I solved the problem. Some hotkeys are identical with other hotkeys, for example E = Extrude. When I changed, it worked. Thanks again because I am an old Maya user. :yes:

vidar_nelson: very interesting script. Would you mind if I added a link to your post in the thread on scripting examples for 2.5?
It is a nice introduction to adding custom functions to the keymap.

Sure, go ahead. :slight_smile:
Although hopefully in the final 2.6 release you will not have to use the second script at all, at the moment it’s just a workaround since you can’t define settings for the properties if you add entries to the keymap by hand.

Hey y’all, i fiddled a bit with vidar’s script and here’s one for toggling “occlude background geometry”:

Not really sure if Syntax is proper, i’ve been expeirmenting with Python for only a week…

You don’t really need a python operator for that, just use the wm.context_toggle operator, like this. Just make sure you add that to the View3D keymap, then you’re sure that it will only be called when a view3d is in context.

Note: The context attribute value is “space_data.occlude_geometry” but the button is not wide enough to show all of it.

As far as your python code though, you can change the exec function for this:

context.space_data.occlude_geometry = not context.space_data.occlude_geometry

The not keyword is the boolean not operator.


Awesome, thanks a lot! Is there a documentation anywhere about writing operators and all the extra stuff like wm.context_toggle?

At this point, not much beside the operator docs:


I try to start this script but it doesn’t work. I running blender 2.5 x64 on windows x64 / ubuntu x64. Maybe that was a problem? Is there solution?


I’m on a 32bit system, but I don’t think that makes a difference.
It’s a bit hard to say what is going wrong for you. Do you get any error messages, or does it simply look like nothing changes?

For clarity, these are the steps I take to get vidar_nelson’s script to work in Blender 2.5 alpha 0:

  • Copy/paste the first codeblock (the one with the ToggleManipulatorMode class) into Blender and run it once (alt+P)
  • Copy/paste the second codeblock into Blender and run it once (alt+P)
  • Go to the User Preferences window and choose as Map: View3D
  • Press the Edit button and scroll to the bottom
  • Expand the last three items (they’re called view3d.manipulator_mode)
  • Next to the hotkey letter (Q, W or E) there is a popup box. For each of the three items, pick ‘Press’
  • Done. Select an object in the 3d-view and you can now change manipulator mode by pressing the Q/W/E buttons on your keyboard.

Here i recorded what i was doing so it will be much clear this way.

Try to restore all keymap configuration before enter the code.

import bpy

kc =[0].active_keyconfig
km = kc.keymaps.get("View3D")
kmi = km.add_item('view3d.manipulator_mode','Q','PRESS') = 1
kmi = km.add_item('view3d.manipulator_mode','W','PRESS') = 2
kmi = km.add_item('view3d.manipulator_mode',"E",'PRESS') = 3

Btw, you don’t need to write the first code. It is already in the op folder.

milan981: In your video you go wrong at 01:20. You shouldn’t quit Blender in between. Just go directly to the user preferences and it will show up over there. Do no start a new instance of Blender.
If you wish the new hotkeys to work every time you start Blender, you need to save them to the default file, after all the other steps you’ve taken (so after you got the hotkeys working).

Yes that was a problem. I enter codes in rex editor without exiting blender and yes now i have those three buttons :slight_smile: