[Bf-funboard] Manipulator

proxe proxe.err0r at gmail.com
Sat Nov 24 09:45:59 CET 2012


Here is the fix for the bad coding i had sent before, i wrote it w/out
testing,

here is the update, its a modification to the class in the experimental
keymap:

def FindKeyMapItems(km, idname):
    items = []
    for kmi in km.keymap_items:
        if kmi.idname == idname:
            items.append(kmi)
    return items

class SetManipulator(bpy.types.Operator):
    """Set's the 3D Manipulator Mode"""
    bl_idname = 'view3d.manipulator_set'
    bl_label = 'Set Manipulator'
    mode = bpy.props.EnumProperty(items=[('TOGGLE', 'Toggle', ""),
                                         ('TRANSLATE', 'Translate', ""),
                                         ('ROTATE', 'Rotate', ""),
                                         ('SCALE', 'Scale', "")],
                                          default='TOGGLE')

    def execute(self, context):
        wm = bpy.context.window_manager

        if self.mode in 'TOGGLE':
            if context.space_data.show_manipulator:
                context.space_data.show_manipulator = 0
            else:
                context.space_data.show_manipulator = 1

        if self.mode in 'TRANSLATE':
            context.space_data.use_manipulator_translate = 1
            context.space_data.use_manipulator_rotate = 0
            context.space_data.use_manipulator_scale = 0

        elif self.mode in 'ROTATE':
            context.space_data.use_manipulator_translate = 0
            context.space_data.use_manipulator_rotate = 1
            context.space_data.use_manipulator_scale = 0

        elif self.mode in 'SCALE':
            context.space_data.use_manipulator_translate = 0
            context.space_data.use_manipulator_rotate = 0
            context.space_data.use_manipulator_scale = 1

        # Switch translate controls over to Manipulator.
        km = wm.keyconfigs.user.keymaps['3D View']
        if context.space_data.show_manipulator:
            for kmi in FindKeyMapItems(km,
                                       'view3d.set_manipulator'):
                kmi.active = 1
            kmi = km.keymap_items['transform.translate']
            kmi.active = 0
            kmi = km.keymap_items['transform.rotate']
            kmi.active = 0
            kmi = km.keymap_items['transform.resize']
            kmi.active = 0
        #Switch it back.
        else:
            for kmi in FindKeyMapItems(km,
                                       'view3d.set_manipulator'):
                kmi.active = 0
            km = wm.keyconfigs.user.keymaps['3D View']
            kmi = km.keymap_items['transform.translate']
            kmi.active = 1
            kmi = km.keymap_items['transform.rotate']
            kmi.active = 1
            kmi = km.keymap_items['transform.resize']
            kmi.active = 1
        return {'FINISHED'}

In order for this to work properly the keymap item that toggles the
manipulator...

kmi = km.keymap_items.new('view3d.set_manipulator', 'SPACE', 'PRESS',
ctrl=1)kmi.properties.mode = 'TOGGLE'

...shouldn't be in the 3D View keymap as you can see above those are
disabled when the
manipulator isnt used, which would also disable the toggle manipulator
keymap item above, I just stuck the keymap item above in the 3D View
Generic Map to avoid this.
also keep in mind tweak transform shouldn't be before the key transform, as
this class disables the first one when manipulator is active.

This isn't what I would call a good solution for this but it is a good way
to test it out for now

Also I did some thinking about adding modes to the current mode, I don't
think this should be default, i.e. pressing a then s would active both
translate and rotate, as this is annoying, holding shift to enable this
behavior isnt a good idea neither as this would disable the use of other
operators or menus that could be applied to those modified keys, finally i
dont think using any other key combination is a good idea as it sort of
breaks the blender standard. idk honestly, what do you guys think?


More information about the Bf-funboard mailing list