Possible bug in addon parameters. Need a guru to verify

Hi all,

I’ve made this small add-on that helps with my workflow on transformation. What it does is check if the transform manipulator is hidden or shown and chose to show the manipulator when pressing G/R/S or use the standard Blender behavior. I do this because I love the manipulators while animating/rigging, but I prefer a smooth uncluttered view while modeling.

The add-on was working perfectly until version 2.63, but with 2.64 on (tested on trunk as well), the parameter that I pass to the function to chose which operation to execute, gets wonky after I select the rotate option (t = 2).

To reproduce the problem, assign view3d.transform_plus to G/R/S keymap in the 3d view, and select from the dropdown the correct operation. Now if you hide the manipulator (CTRL+Space) and use the keys, normal Blender behavior is invoked. When you show the manipulator, pressing the key will cycle true grab, rotate, scale except for when you go back to the translate one, in which case it doesn’t work anymore (you can see the print statement returning 2 even if you press G).

Note that if you press R twice with the manipulator on, it’s supposed to be hiding temporarily the manipulator without disabling it.


 bl_info = {
    'name': 'Transform Plus',
    'author': 'Gianmichele Mariani',
    'version': (1, 0 ,0),
    'blender': (2, 6, 1),
    'location': 'Bind the operator to your transform keys ',
    'description': 'Interaction model based on manipulator visibility',
    'category': '3D View'}

import bpy

def main(context, t):
    
    space = context.space_data
    #space.show_manipulator = not space.show_manipulator
    print(t)

    # Translate
    if t=="1":
        if space.show_manipulator:
             
            if space.use_manipulator_translate:
                bpy.ops.view3d.enable_manipulator('INVOKE_DEFAULT', translate=False, rotate=False, scale=False)
            else:        
                bpy.ops.view3d.enable_manipulator('INVOKE_DEFAULT', translate=True, rotate=False, scale=False)
        else:
            bpy.ops.transform.translate('INVOKE_DEFAULT')
     
     # Rotate
    elif t=="2":
        if space.show_manipulator:
             
            if space.use_manipulator_rotate:
                bpy.ops.view3d.enable_manipulator('INVOKE_DEFAULT', translate=False, rotate=False, scale=False)
            else:        
                bpy.ops.view3d.enable_manipulator('INVOKE_DEFAULT', translate=False, rotate=True, scale=False)
        else:
            bpy.ops.transform.rotate('INVOKE_DEFAULT')
         
     # Scale
    elif t=="3":    
        if space.show_manipulator:
             
            if space.use_manipulator_scale:
                bpy.ops.view3d.enable_manipulator('INVOKE_DEFAULT', translate=False, rotate=False, scale=False)
            else:        
                bpy.ops.view3d.enable_manipulator('INVOKE_DEFAULT', translate=False, rotate=False, scale=True)
        else:
            bpy.ops.transform.resize('INVOKE_DEFAULT')             
    


class TransformPlus(bpy.types.Operator):
    '''Transform Plus'''
    bl_idname = "view3d.transform_plus"
    bl_label = "Transform Plus"
    
    values = [  ( "1", "Translate", "Translate" ), 
                ( "2", "Rotate", "Rotate" ),
                ( "3", "Scale", "Scale" )] 
              
    tool = bpy.props.EnumProperty(name="Tool", items=values, description="Choose an operator")

    @classmethod
    def poll(cls, context):
        return context.space_data.type == 'VIEW_3D'
    
    def execute(self, context):
        main(context, self.properties.tool)
        return{'FINISHED'}


def register():
    bpy.utils.register_class(TransformPlus)


def unregister():
    bpy.utils.unregister_class(TransformPlus)


if __name__ == "__main__":
    register()

I have not tested if this is a bug or not, but you can try this method:


import bpy
from bpy.props import *
from bpy.types import Operator, Menu

class VIEW3D_OT_set_manipulation(Operator):
    "Set's the 3D Manipulator Mode"
    bl_idname = 'view3d.set_manipulation'
    bl_label = 'Set Manipulation'
    
    mode = EnumProperty(items=[('TRANSLATE',
                            'Translate',
                            "Activate the transform mode for the manipulator or perform the transform operation"),
                           ('ROTATE',
                            'Rotate',
                            "Activat the rotate mode for the manipulator or perform the rotate operation"),
                           ('SCALE',
                            'Scale',
                            "Activate the scale mode for the manipulator or perform the resize operation")],
                            default='TRANSLATE')
    
    toggle = BoolProperty(name='Toggle',
                      description="If used it is possible for more then one manipulator to be active at a time.",
                      default=True)
    
    @classmethod
    def poll (cls, context):
        return context.space_data.type in 'VIEW_3D'
       
    def execute(self, context):
        space = context.space_data
    
        if self.mode in 'TRANSLATE':
            if space.show_manipulator:
                if space.use_manipulator_translate:
                    if self.toggle:
                        space.use_manipulator_translate = False
                    else:
                        space.use_manipulator_translate = False
                        space.use_manipulator_rotate = False
                        space.use_manipulator_scale = False
                else:
                    if self.toggle:
                        space.use_manipulator_translate = True
                    else:
                        space.use_manipulator_translate = True
                        space.use_manipulator_rotate = False
                        space.use_manipulator_scale = False
            else:
                bpy.ops.transform.translate('INVOKE_DEFAULT')
    
        elif self.mode in 'ROTATE':
            if space.show_manipulator:
                if space.use_manipulator_rotate:
                    if self.toggle:
                        space.use_manipulator_rotate = False
                    else:
                        space.use_manipulator_translate = False
                        space.use_manipulator_rotate = False
                        space.use_manipulator_scale = False
                else:
                    if self.toggle:
                        space.use_manipulator_rotate = True
                    else:
                        space.use_manipulator_translate = False
                        space.use_manipulator_rotate = True
                        space.use_manipulator_scale = False
            else:
                bpy.ops.transform.rotate('INVOKE_DEFAULT')
    
        elif self.mode in 'SCALE':
            if space.show_manipulator:
                if space.use_manipulator_scale:
                    if self.toggle:
                        space.use_manipulator_scale = False
                    else:
                        space.use_manipulator_translate = False
                        space.use_manipulator_rotate = False
                        space.use_manipulator_scale = False
                else:
                    if self.toggle:
                        space.use_manipulator_scale = True
                    else:
                        space.use_manipulator_translate = False
                        space.use_manipulator_rotate = False
                        space.use_manipulator_scale = True
            else:
                bpy.ops.transform.resize('INVOKE_DEFAULT')
            
        return {'FINISHED'}

EDIT - Not really easy to read, white space is being removed, one of the more annoying features of blender artists.