aditiapratama
11/22/2016 - 4:11 AM

Blender F-Curve Unlock Editability

Blender F-Curve Unlock Editability

import bpy

bl_info = {
    "name": "F-Curve Unlock Editability",
    "description": "This script will allow you to select X,Y,Z Channel for multiple objects selected",
    "author": "Aditia A. Pratama",
    "version": (0, 0, 1),
    "blender": (2, 75, 0),
    "location": "F-Curve Editor > Tools",
    "warning": "This is an unstable version",
    "wiki_url": "",
    "category": "Animation" }

import bpy

class FSUnlockXLoc(bpy.types.Operator):
    'Unlock only x location for all objects in F-Curve'
    bl_idname = 'fcurve.unlock_x_loc'
    bl_label = 'Unock X Location Channel Only for All Selected Objects'

    def execute(self, context,):
        for ob in bpy.context.selected_editable_objects:
            if ob.animation_data is not None and ob.animation_data.action is not None:
                action = ob.animation_data.action
                for fcu in action.fcurves:
                    fcu.select = True
                    fcu.lock = True
                    if fcu.array_index == 0 and fcu.data_path == "location":
                        fcu.lock = False
                        fcu.select = True
        return {'FINISHED'}

class FSUnlockYLoc(bpy.types.Operator):
    'Unlock only y location for all objects in F-Curve'
    bl_idname = 'fcurve.unlock_y_loc'
    bl_label = 'Unock Y Location Channel Only for All Selected Objects'

    def execute(self, context,):
        for ob in bpy.context.selected_editable_objects:
            if ob.animation_data is not None and ob.animation_data.action is not None:
                action = ob.animation_data.action
                for fcu in action.fcurves:
                    fcu.select = True
                    fcu.lock = True
                    if fcu.array_index == 1 and fcu.data_path == "location":
                        fcu.lock = False
                        fcu.select = True
        return {'FINISHED'}

class FSUnlockZLoc(bpy.types.Operator):
    'Unlock only z location for all objects in F-Curve'
    bl_idname = 'fcurve.unlock_z_loc'
    bl_label = 'Unock z Location Channel Only for All Selected Objects'

    def execute(self, context,):
        for ob in bpy.context.selected_editable_objects:
            if ob.animation_data is not None and ob.animation_data.action is not None:
                action = ob.animation_data.action
                for fcu in action.fcurves:
                    fcu.select = True
                    fcu.lock = True
                    if fcu.array_index == 2 and fcu.data_path == "location":
                        fcu.lock = False
                        fcu.select = True
        return {'FINISHED'}

class FSUnLockLoc(bpy.types.Operator):
    'UnLock location for all objects in F-Curve'
    bl_idname = 'fcurve.unlock_loc'
    bl_label = 'Unlock Location Channel for All Selected Objects'

    def execute(self, context,):
        for ob in bpy.context.selected_editable_objects:
            if ob.animation_data is not None and ob.animation_data.action is not None:
                action = ob.animation_data.action
                for fcu in action.fcurves:
                    if fcu.data_path == "location":
                        fcu.lock = False
                        fcu.select = False
        return {'FINISHED'}

def menu_func_fcurveunlock(self, context,):
    layout = self.layout
    col = layout.column()
    row = col.row(align=True)
    row.alignment = 'CENTER'
    row.operator("fcurve.unlock_x_loc", text="X")
    row.operator("fcurve.unlock_y_loc", text="Y")
    row.operator("fcurve.unlock_z_loc", text="Z")
    row.operator("fcurve.unlock_loc",  text="All")

def register():
    bpy.utils.register_module(__name__)
    bpy.types.GRAPH_HT_header.append(menu_func_fcurveunlock)

def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.GRAPH_HT_header.remove(menu_func_fcurveunlock)

if __name__ == "__main__":
    register()