Unlock / Unhide Channels

* Copy the script below to the clipboard and paste it into Maya/Script Editor to be able to execute.

#Unlock + unhide Channels Script
#Author: Jiuyang Wang
#This script is to unlock and/or unhide checked attributes of the selected transforms. (Quick select doesn't work if the
#shapes have the same name but different transforms)

import maya.cmds as cmds

def create_UI():
    script_ui = 'Unlock/unhide Channels' #The name of the UI
    ui_width = 300 #The width of the UI
    #get the selected items which the type is a transform
    selected = cmds.ls(selection = True, type = 'transform')

    #if the window has already existed, then delete the one.
    if cmds.window(script_ui, exists = True):
            cmds.deleteUI(script_ui)

    #create the ui window
    wd = cmds.window(script_ui, width = ui_width, title = 'Unlock/Unhide Channels') 
    
    #The main layout (top of the hierarchy)
    main_layout = cmds.rowColumnLayout()
    
    #construct the layout for the select funtion
    selectWidth = [(1, ui_width*0.6), (2, ui_width*0.4)] #The width setting for the columns
    #define the select function's base layout
    select_layout = cmds.rowColumnLayout(numberOfColumns = 2, width = ui_width, columnWidth = selectWidth)
    #create a text element
    cmds.text(label = 'Select:', align = 'left', width = selectWidth[0][1])
    #create a button that is to select all the transforms in the scene (keyword included)
    cmds.button(label = 'Select All',command = lambda *args: select_all(txt, selected), width = selectWidth[1][1])
    #move the elements to the hierarchy
    cmds.setParent('..')
    
    #create the secondary layout of the select function
    sec_selectWidth = [(1,ui_width*0.25), (2,ui_width*0.25),(3, ui_width*0.25),(4,ui_width*0.25)] #The width setting for the columnbs
    #define the layout
    sec_select_layout = cmds.rowColumnLayout(numberOfColumns = 4, width = ui_width, columnWidth = sec_selectWidth)
    #create a button which is to select all the curves in the scene(keyword included)
    cmds.button(label = 'Curves', command = lambda *args: select_Curves(txt, selected))
    #create a button which is to select all the polygons in the scene(keyword included)
    cmds.button(label = 'Polygons',command = lambda *args: select_Polygons(txt, selected))
    #create a text element which explains the textfield
    cmds.text(label = 'with Keyword:', align = 'right', width = sec_selectWidth[2][1])
    #create a textfield which is to input the keyword (filter)
    txt = cmds.textField(width = sec_selectWidth[3][1])
    #move the elements to the hierarchy
    cmds.setParent('..')
    #separators
    cmds.separator(visible = False)
    cmds.separator(visible = False)
    cmds.separator(visible = False)
    cmds.separator(visible = False)
    #move the elements to the hierarchy
    cmds.setParent('..')
    
    #create the layout for the select channel function
    channel_layout = cmds.rowColumnLayout(numberOfColumns = 2, width = ui_width)
    #create a text element
    cmds.text(label = 'Channels:', align = 'left')
    #move the elements to the hierarchy
    cmds.separator(visible = False)
    
    #create the secondary channel layout
    sec_channel_width = [(1,ui_width*0.4), (2,ui_width*0.2),(3,ui_width*0.2),(4,ui_width*0.2)]#the width setting
    #define the layout
    sec_channel_layout = cmds.rowColumnLayout(numberOfColumns = 4, width = ui_width, columnWidth = sec_channel_width)
    
    #first row: Translations
    #create a button which is to check all the translations checkbox
    cmds.button(label = 'All Translations', command = lambda *args: translate_all(tx,ty,tz))
    #checkbox for xyz
    tx = cmds.checkBox(label = 'X')
    ty = cmds.checkBox(label = 'Y')
    tz = cmds.checkBox(label = 'Z')
    
    #second row: Rotations
    #create a button which is to check all the rotation checkboxes
    cmds.button(label = 'All Rotations', command = lambda *args: rotate_all(rx, ry, rz))
    #checkbox for xyz
    rx = cmds.checkBox(label = 'X')
    ry = cmds.checkBox(label = 'Y')#, onCommand = lambda *args: translate_x(), offCommand = lambda *args: translate_all())
    rz = cmds.checkBox(label = 'Z')
    
    #third row: scales
    #create a button which is to check all the scale checkboxes
    cmds.button(label = 'All Scales', command = lambda *args: scale_all(sx, sy, sz))
    #checkbox for xyz
    sx = cmds.checkBox(label = 'X')
    sy = cmds.checkBox(label = 'Y')
    sz = cmds.checkBox(label = 'Z')
    
    #Create tertiary layout for the channel checkbox
    th_channel_width = [(1,ui_width*0.4), (2,ui_width*0.3),(3,ui_width*0.3)]#width setting
    #define the layout
    th_channel_layout = cmds.rowColumnLayout(numberOfColumns = 3, width = ui_width, columnWidth = th_channel_width) 
    #separator
    cmds.separator(visible = False) 
    #create a checkbox for the channel visibility.
    vis = cmds.checkBox(label = 'Visibility')
    #create a checkbox for all the channel (in case of a unsepecified channel)
    all_c = cmds.checkBox(label = 'All Channels', onCommand = lambda *args: all_channels(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis), offCommand = lambda *args: channels_off(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis))
    #move the element to the hierarchy
    cmds.setParent('..')
    
    #separators
    cmds.separator(visible = False)
    cmds.separator(visible = False)
    cmds.separator(visible = False)    
    
    #create the layout for the function buttons
    button_width = [(1,ui_width*0.25), (2,ui_width*0.25), (3,ui_width*0.5)]#the width setting
    #define the layout
    button_layout = cmds.rowColumnLayout(numberOfColumns = 3, width = ui_width, columnWidth = button_width)
    #create a button that is to unlock the checked channels
    cmds.button(label = 'Unlock', command = lambda *args: unlock(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis))
    #create a button that is to unhide the checked channels
    cmds.button(label = 'Unhide', command = lambda *args: unhide(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis))
    #create a button that is to unlock and unhide the checked channels
    cmds.button(label = 'Unlock + Unhide', command = lambda *args: unlock_unhide(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis))
    
    #display the window
    cmds.showWindow(wd)
    

def select_all(txt, selection):
    #get the keyword from the textfield
    key = cmds.textField(txt, q=1, text=1)
    #get the transforms that contains the keyword
    sceneAll = cmds.ls('*{0}*'.format(key),type = 'transform')
    #add the transforms to the current selection
    cmds.select(sceneAll, add = True)
    
def select_Curves(txt, selection):
    #get the keyword from the textfield
    key = cmds.textField(txt, q=1, text=1)
    #get the transforms that contains the keyword
    sceneAll = cmds.ls('*{0}*'.format(key),type = 'transform')
    #check if the list contains curves
    for item in sceneAll:
        #get the shape of the item
        sp = cmds.listRelatives(item, shapes=True)
        #check if the type of the shape is a curve
        if sp:
            if cmds.nodeType(item+'|'+sp[0]) == 'nurbsCurve':
                cmds.select(item, add = True)
            #add the transform to the current selection
        
def select_Polygons(txt, selection):
    #get the keyword from the textfield
    key = cmds.textField(txt, q=1, text=1)
    #get the transforms that contains the keyword
    sceneAll = cmds.ls('*{0}*'.format(key),type = 'transform')
    #check if the list contains mesh
    for item in sceneAll:
        #get the shape of the item
        sp = cmds.listRelatives(item, shapes=True)
        #check if the type of the shape is a mesh
        if sp:
            if cmds.nodeType(item+'|'+sp[0]) == 'mesh':
                cmds.select(item, add = True)
                #add the transform to the current selection
    
def translate_all(translate_x, translate_y, translate_z):
    #check the translations
    cmds.checkBox(translate_x, e = True, value = True)
    cmds.checkBox(translate_y, e = True, value = True)
    cmds.checkBox(translate_z, e = True, value = True)

def rotate_all(rotate_x, rotate_y, rotate_z):
    #check the rotations
    cmds.checkBox(rotate_x, e = True, value = True)
    cmds.checkBox(rotate_y, e = True, value = True)
    cmds.checkBox(rotate_z, e = True, value = True)

def scale_all(scale_x, scale_y, scale_z):
    #check the scales
    cmds.checkBox(scale_x, e = True, value = True)
    cmds.checkBox(scale_y, e = True, value = True)
    cmds.checkBox(scale_z, e = True, value = True)
    
def all_channels(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis):
    #check all the channels
    cmds.checkBox(tx, e = True, value = True)
    cmds.checkBox(ty, e = True, value = True)
    cmds.checkBox(tz, e = True, value = True)
    cmds.checkBox(rx, e = True, value = True)
    cmds.checkBox(ry, e = True, value = True)
    cmds.checkBox(rz, e = True, value = True)
    cmds.checkBox(sx, e = True, value = True)
    cmds.checkBox(sy, e = True, value = True)
    cmds.checkBox(sz, e = True, value = True)
    cmds.checkBox(vis, e = True, value = True)

def channels_off(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis):
    #uncheck all the channels
    cmds.checkBox(tx, e = True, value = False)
    cmds.checkBox(ty, e = True, value = False)
    cmds.checkBox(tz, e = True, value = False)
    cmds.checkBox(rx, e = True, value = False)
    cmds.checkBox(ry, e = True, value = False)
    cmds.checkBox(rz, e = True, value = False)
    cmds.checkBox(sx, e = True, value = False)
    cmds.checkBox(sy, e = True, value = False)
    cmds.checkBox(sz, e = True, value = False)
    cmds.checkBox(vis, e = True, value = False)
    

def unlock(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis):
    #get the current selection
    selection = cmds.ls(selection = True, type = 'transform')
    #get the status of the checkboxes
    tx_result = cmds.checkBox(tx, query=True, value=True)
    ty_result = cmds.checkBox(ty, query=True, value=True)
    tz_result = cmds.checkBox(tz, query=True, value=True)
    rx_result = cmds.checkBox(rx, query=True, value=True)
    ry_result = cmds.checkBox(ry, query=True, value=True)
    rz_result = cmds.checkBox(rz, query=True, value=True)
    sx_result = cmds.checkBox(sx, query=True, value=True)
    sy_result = cmds.checkBox(sy, query=True, value=True)
    sz_result = cmds.checkBox(sz, query=True, value=True)
    vis_result = cmds.checkBox(vis, query=True, value=True)
    #check if the user selected smt
    if selection:
        #if no attributes checked
        if tx_result or ty_result or tz_result or rx_result or ry_result or rz_result or sx_result or sy_result or sz_result or vis_result:
            #for loop to check every item in the selection
            for sel in selection:
                #check if the item is a transform
                if cmds.objectType(sel) == 'transform':
                    #check if translateX is checked 
                    if tx_result:
                        #check if sel's translateX attribute is locked 
                        if cmds.getAttr(sel+'.translateX', lock = True):
                            #unlock translateX
                            cmds.setAttr(sel+'.translateX', lock = False)
                            print 'Successfully unlocked ' + sel+' translateX'
                        else:#if sel's translateX isn't locked
                            #print a message
                            print 'The channel translateX of '+sel+' is not locked'
                        
                    #check if translateY is checked
                    if ty_result:
                        #check if sel's translateY attribute is locked 
                        if cmds.getAttr(sel+'.translateY', lock = True):
                            #unlock translateY
                            cmds.setAttr(sel+'.translateY', lock = False)
                            print 'Successfully unlocked ' + sel+' translateY'
                        else:#if sel's translateY isn't locked
                            #print a message
                            print 'The channel translateY of '+sel+' is not locked'
                            
                    #check if translateZ is checked
                    if tz_result:
                        #check if sel's translateZ attribute is locked 
                        if cmds.getAttr(sel+'.translateZ', lock = True):
                            #unlock translateZ
                            cmds.setAttr(sel+'.translateZ', lock = False)
                            print 'Successfully unlocked ' + sel+' translateZ'
                        else:#if sel's translateZ isn't locked
                            #print a message
                            print 'The channel translateZ of '+sel+' is not locked'
                            
                    #check if rotateX is checked
                    if rx_result:
                        #check if sel's rotateX attribute is locked 
                        if cmds.getAttr(sel+'.rotateX', lock = True):
                            #unlock rotateX
                            cmds.setAttr(sel+'.rotateX', lock = False)
                            print 'Successfully unlocked ' + sel+' rotateX'
                        else:#if sel's rotateX isn't locked
                            #print a message
                            print 'The channel rotateX of '+sel+' is not locked'
                            
                    #check if rotateY is checked
                    if ry_result:
                        #check if sel's rotateY attribute is locked 
                        if cmds.getAttr(sel+'.rotateY', lock = True):
                            #unlock rotateY
                            cmds.setAttr(sel+'.rotateY', lock = False)
                            print 'Successfully unlocked ' + sel+' rotateY'
                        else:#if sel's rotateY isn't locked
                            #print a message
                            print 'The channel rotateY of '+sel+' is not locked'
                     
                    #check if rotateZ is checked
                    if rz_result:
                        #check if sel's rotateZ attribute is locked 
                        if cmds.getAttr(sel+'.rotateZ', lock = True):
                            #unlock rotateZ
                            cmds.setAttr(sel+'.rotateZ', lock = False)
                            print 'Successfully unlocked ' + sel+' rotateZ'
                        else:#if sel's rotateZ isn't locked
                            #print a message
                            print 'The channel rotateZ of '+sel+' is not locked'
                    
                    #check if scaleX is checked
                    if sx_result:
                        #check if sel's scaleX attribute is locked 
                        if cmds.getAttr(sel+'.scaleX', lock = True):
                            #unlock scaleX
                            cmds.setAttr(sel+'.scaleX', lock = False)
                            print 'Successfully unlocked ' + sel+' scaleX'
                        else:#if sel's scaleX isn't locked
                            #print a message
                            print 'The channel scaleX of '+sel+' is not locked'
                            
                    #check if scaleY is checked
                    if sy_result:
                        #check if sel's scaleY attribute is locked 
                        if cmds.getAttr(sel+'.scaleY', lock = True):
                            #unlock scaleY
                            cmds.setAttr(sel+'.scaleY', lock = False)
                            print 'Successfully unlocked ' + sel+' scaleY'
                        else:#if sel's scaleY isn't locked
                            #print a message
                            print 'The channel scaleY of '+sel+' is not locked'
                            
                    #check if scaleZ is checked
                    if sz_result:
                        #check if sel's scaleZ attribute is locked 
                        if cmds.getAttr(sel+'.scaleZ', lock = True):
                            #unlock scaleZ
                            cmds.setAttr(sel+'.scaleZ', lock = False)
                            print 'Successfully unlocked ' + sel+' scaleZ'
                        else:#if sel's scaleZ isn't locked
                            #print a message
                            print 'The channel scaleZ of '+sel+' is not locked'
                            
                    #check if visibility is checked
                    if vis_result:
                        #check if sel's visibility attribute is locked 
                        if cmds.getAttr(sel+'.visibility', lock = True):
                            #unlock visibility
                            cmds.setAttr(sel+'.visibility', lock = False)
                            print 'Successfully unlocked ' + sel+' visibility'
                        else:#if sel's visibility isn't locked
                            #print a message
                            print 'The channel visibility of '+sel+' is not locked'
                else:
                    print sel + ' is not a valid transform. The program skipped it.'
        else:
            cmds.warning('No attributes checked. Please check the attribute that needs to be unlock or unhide.')
    else:
        #if the uset selected nothing, then show a warning
        cmds.warning('Nothing selected. Please select transforms that need to unlock/unhide attributes.')

def unhide(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis):
    #get the current selection
    selection = cmds.ls(selection = True, type = 'transform')
    #get the status of the checkboxes
    tx_result = cmds.checkBox(tx, query=True, value=True)
    ty_result = cmds.checkBox(ty, query=True, value=True)
    tz_result = cmds.checkBox(tz, query=True, value=True)
    rx_result = cmds.checkBox(rx, query=True, value=True)
    ry_result = cmds.checkBox(ry, query=True, value=True)
    rz_result = cmds.checkBox(rz, query=True, value=True)
    sx_result = cmds.checkBox(sx, query=True, value=True)
    sy_result = cmds.checkBox(sy, query=True, value=True)
    sz_result = cmds.checkBox(sz, query=True, value=True)
    vis_result = cmds.checkBox(vis, query=True, value=True)
    #check if the user selected smt
    if selection:
        #if no attributes checked
        if tx_result or ty_result or tz_result or rx_result or ry_result or rz_result or sx_result or sy_result or sz_result or vis_result:
            #for loop to check every item in the selection
            for sel in selection:
                #check if the item is a transform
                if cmds.objectType(sel) == 'transform':
                    #check if translateX is checked 
                    if tx_result:
                        #check if sel's translateX attribute is hidden 
                        if not cmds.getAttr(sel+'.translateX', keyable = True):
                            #unhide translateX
                            cmds.setAttr(sel+'.translateX', keyable = True)
                            print 'Successfully unhide ' + sel+' translateX'
                        else:#if sel's translateX isn't hidden
                            #print a message
                            print 'The channel translateX of '+sel+' is not hidden'
                        
                    #check if translateY is checked
                    if ty_result:
                        #check if sel's translateY attribute is hidden 
                        if not cmds.getAttr(sel+'.translateY', keyable = True):
                            #unhide translateY
                            cmds.setAttr(sel+'.translateY', keyable = True)
                            print 'Successfully unhide ' + sel+' translateY'
                        else:#if sel's translateY isn't hidden
                            #print a message
                            print 'The channel translateY of '+sel+' is not hidden'
                            
                    #check if translateZ is checked
                    if tz_result:
                        #check if sel's translateZ attribute is hidden 
                        if not cmds.getAttr(sel+'.translateZ', keyable = True):
                            #unhide translateZ
                            cmds.setAttr(sel+'.translateZ', keyable = True)
                            print 'Successfully unhide ' + sel+' translateZ'
                        else:#if sel's translateZ isn't hidden
                            #print a message
                            print 'The channel translateZ of '+sel+' is not hidden'
                            
                    #check if rotateX is checked
                    if rx_result:
                        #check if sel's rotateX attribute is hidden 
                        if not cmds.getAttr(sel+'.rotateX', keyable = True):
                            #unhide rotateX
                            cmds.setAttr(sel+'.rotateX', keyable = True)
                            print 'Successfully unhide ' + sel+' rotateX'
                        else:#if sel's rotateX isn't hidden
                            #print a message
                            print 'The channel rotateX of '+sel+' is not hidden'
                            
                    #check if rotateY is checked
                    if ry_result:
                        #check if sel's rotateY attribute is hidden 
                        if not cmds.getAttr(sel+'.rotateY', keyable = True):
                            #unhide rotateY
                            cmds.setAttr(sel+'.rotateY', keyable = True)
                            print 'Successfully unhide ' + sel+' rotateY'
                        else:#if sel's rotateY isn't hidden
                            #print a message
                            print 'The channel rotateY of '+sel+' is not hidden'
                     
                    #check if rotateZ is checked
                    if rz_result:
                        #check if sel's rotateZ attribute is hidden 
                        if not cmds.getAttr(sel+'.rotateZ', keyable = True):
                            #unhide rotateZ
                            cmds.setAttr(sel+'.rotateZ', keyable = True)
                            print 'Successfully unhide ' + sel+' rotateZ'
                        else:#if sel's rotateZ isn't hidden
                            #print a message
                            print 'The channel rotateZ of '+sel+' is not hidden'
                    
                    #check if scaleX is checked
                    if sx_result:
                        #check if sel's scaleX attribute is hidden 
                        if not cmds.getAttr(sel+'.scaleX', keyable = True):
                            #unhide scaleX
                            cmds.setAttr(sel+'.scaleX', keyable = True)
                            print 'Successfully unhide ' + sel+' scaleX'
                        else:#if sel's scaleX isn't hidden
                            #print a message
                            print 'The channel scaleX of '+sel+' is not hidden'
                            
                    #check if scaleY is checked
                    if sy_result:
                        #check if sel's scaleY attribute is hidden 
                        if not cmds.getAttr(sel+'.scaleY', keyable = True):
                            #unhide scaleY
                            cmds.setAttr(sel+'.scaleY', keyable = True)
                            print 'Successfully unhide ' + sel+' scaleY'
                        else:#if sel's scaleY isn't hidden
                            #print a message
                            print 'The channel scaleY of '+sel+' is not hidden'
                            
                    #check if scaleZ is checked
                    if sz_result:
                        #check if sel's scaleZ attribute is hidden 
                        if not cmds.getAttr(sel+'.scaleZ', keyable = True):
                            #unhide scaleZ
                            cmds.setAttr(sel+'.scaleZ', keyable = True)
                            print 'Successfully unhide ' + sel+' scaleZ'
                        else:#if sel's scaleZ isn't hidden
                            #print a message
                            print 'The channel scaleZ of '+sel+' is not hidden'
                            
                    #check if visibility is checked
                    if vis_result:
                        #check if sel's visibility attribute is hidden 
                        if not cmds.getAttr(sel+'.visibility', keyable = True):
                            #unhide visibility
                            cmds.setAttr(sel+'.visibility', keyable = True)
                            print 'Successfully unhide ' + sel+' visibility'
                        else:#if sel's visibility isn't hidden
                            #print a message
                            print 'The channel visibility of '+sel+' is not hidden'
                else:
                    print sel + ' is not a valid transform. The program skipped it.'
        else:
            cmds.warning('No attributes checked. Please check the attribute that needs to be unlock or unhide.')
    else:
        #if the uset selected nothing, then show a warning
        cmds.warning('Nothing selected. Please select transforms that need to unlock/unhide attributes.')

def unlock_unhide(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis):
    #unlock attributes
    unlock(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis)
    #unhide attributes
    unhide(tx, ty, tz, rx, ry, rz, sx, sy, sz, vis)
    
create_UI()

© Jiuyang Wang │ 778-926-0288 │ einjw2999@gmail.com