Python / MEL

Python: Maya: Setting up an Enviroment

To load and reference external Python files, add a PYTONPATH to Maya.env file prior to starting up Maya. The location of the Maya.env file will be located in the following folders:

  • Windows: <drive>:\Documents and Settings\<username>\My Documents\maya\<Version>
  • Mac OS X: ~/Library/Preferences/Autodesk/maya/<version>
  • Linux: ~/maya/<version>

While in the Maya.env file, write the following line (this is a Windows example):

PYTHONPATH = F:\Work\Python\Maya

In a empty folder that is going to contain external python files, create an empty __init__.py file. This file tells Python to treat the folder it resides in as containing Python Packages. Doing this will prevent folders with common names from unintentionally hiding valid modules.

Once all this is set up and Maya is loaded, all the .py files should get recompiled as .pyc files.Save the Maya.env and load Maya.

In Maya’s Python script Editor, import the .py file that contains the Python function the you want to call; example:

import riggingtools
riggingtools.createIk

Python: Maya: Set Up Wing FLex

# USE : returns a limited list of nodes based on a breakerObj. Use it return only the joints of a leg rig prior to the foot joints for instance
# REQUIRES:
#     1. filterSelection()
#    2. checkAttrExist()
#    3. addBaseNode()
#    4. whichAxis(value)
#    5. editTxtGrpButtonArray
#    6. deleteWindow()
# NOTES : 
# 1. ctrlArray = select the main controls
# 2. locatorArray = select the locators that coincide with the main controls
# 1. flexAxis = axis that flex will locators will rotate on. Make sure that all the main controls axis match the locator axis

def setUpWingFlex(ctrlArray,locatorArray,flexAxis):
    returnArray = []
    keepVectors = []
    tweenLoc = []
    flexAttr = 'flex'
    checkAttrExist(ctrlArray[0],flexAttr,'double',-50,50,0,True,True)
    
    previousCtrl = ctrlArray[0]
    previousLocator = locatorArray[0]
    
    maya.cmds.select(previousLocator, hi=True)
    allLoc = maya.cmds.ls(selection=True,tr=True)
    
    for j in range(1,len(ctrlArray),1):
        if(j < len(ctrlArray)):
            #print('setUpWingFlex2 :: j = ' + str(j))
            #print('setUpWingFlex2 :: locatorArray[j-1] = ' + str(locatorArray[j-1]))
            temp = maya.cmds.listRelatives(locatorArray[j-1],c=True,typ='transform')
            #print('setUpWingFlex2 :: temp = ' + str(temp))
            tempArray = filterSelection(temp,locatorArray[j],1)
            for i in tempArray:
                #print('setUpWingFlex2 :: i = ' + str(i))
                tweenLoc.append(i)
            
            if(j == len(ctrlArray)-1):
                children = maya.cmds.listRelatives(locatorArray[j],c=True,typ='transform')
                #print('setUpWingFlex2 :: Checking to see if last locator (' + str(locatorArray[j]) + ') has children ')
                if(children != None):
                    for c in children:
                        #print('setUpWingFlex2 :: ' + str(locatorArray[j]) + ') has child : ' + str(c))
                        tweenLoc.append(c)

    #print('setUpWingFlex2 :: tweenLoc ' + str(tweenLoc))

    grpNodes = addBaseNode(allLoc)
    grpCTRL = addBaseNode(ctrlArray)

    for j in range(0,len(ctrlArray),1):
        destination = locatorArray[j] + '.rx'# + rotateAxis.lower()
        source = ctrlArray[j] + '.rx'# + rotateAxis.lower()
        maya.cmds.connectAttr(source, destination, force=True)

        destination = locatorArray[j] + '.ry'# + pitchAxis.lower()
        source = ctrlArray[j] + '.ry'# + pitchAxis.lower()
        maya.cmds.connectAttr(source, destination, force=True)

        destination = locatorArray[j] + '.rz'# + rollAxis.lower()
        source = ctrlArray[j] + '.rz'# + rollAxis.lower()
        maya.cmds.connectAttr(source, destination, force=True)
        
        constainLocator = maya.cmds.pointConstraint(locatorArray[j], ctrlArray[j], weight=1 )

    source = ctrlArray[0] + '.' + flexAttr
    for i in tweenLoc:
        destination = i + '.r' + flexAxis.lower()
        maya.cmds.connectAttr(source, destination, force=True)
    
    return returnArray
    
###############################################################################################
#     GUI:    
###############################################################################################
#mainLocators = maya.cmds.ls(selection=True)


def editTxtGrpButtonArray(name,type):
    array = maya.cmds.ls(selection=True)
    out = ''
    for i in array:
        out = out + i + '    '
        
    if(type == 'textFieldButtonGrp'):
        maya.cmds.textFieldButtonGrp( name, e=True, text=out)

def whichAxis(value):
    axis = ['x','X']
    if(value == 2):
        axis = ['y','Y']
    elif(value == 3):
        axis = ['z','Z']
    return axis


def buildWindow(windowName,windowTitle, line1,line2,line3):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 300))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')
    #form = maya.cmds.formLayout(windowName + '_form1')
    #tabs = maya.cmds.tabLayout(windowName + '_tabs1', innerMarginWidth=5, innerMarginHeight=5)
    #maya.cmds.formLayout( form, edit=True, attachForm=[(tabs, 'top', 0), (tabs, 'left', 0), (tabs, 'bottom', 0), (tabs, 'right', 0)] )
    
    #maya.cmds.columnLayout('')
    #maya.cmds.scrollLayout('Global' , width=500, height=300, horizontalScrollBarThickness=16, verticalScrollBarThickness=16)

    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldButtonGrp( windowName + '_mainCtrls', label='Get Controls:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_mainCtrls' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line2 )
    maya.cmds.textFieldButtonGrp( windowName + '_mainLocators', label='Get Locators:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_mainLocators' + '","textFieldButtonGrp")' )
    maya.cmds.radioButtonGrp( windowName + '_flexRotateAxis', label='Joint Aim Axis:', labelArray3=['X', 'Y', 'Z'], numberOfRadioButtons=3, en=True, sl=2 )
    maya.cmds.text( label= '' )
    maya.cmds.text( label= line3 )
    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.button(label='?', height = questionButtonHeight)
    maya.cmds.text( label= '   ' )
    maya.cmds.button(label='?', height = questionButtonHeight)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):
    getCtrls = maya.cmds.textFieldButtonGrp( windowName + '_mainCtrls', q=True, text=True )
    getLocators = maya.cmds.textFieldButtonGrp( windowName + '_mainLocators', q=True, text=True )
    ctrls = getCtrls.split()
    locators = getLocators.split()

    fra = maya.cmds.radioButtonGrp( windowName + '_flexRotateAxis', q=True, sl=True )
    flexAxis = whichAxis(fra)[1]
    #jua = maya.cmds.radioButtonGrp( windowName + '_jointUpAxis', q=True, sl=True )
    #pitchAxis = whichAxis(jua)[1]
    #jra = maya.cmds.radioButtonGrp( windowName + '_jointRotAxis', q=True, sl=True )
    #rotateAxis = whichAxis(jra)[1]

    #print ('rollAxis = ' + str(rollAxis) )
    #print ('rotateAxis = ' + str(rotateAxis) )
    #print ('pitchAxis = ' + str(pitchAxis) )
    
    setUpWingFlex2(ctrls,locators,flexAxis)


line1 = '    SELECT THE MAIN CONTROLS:-'
line2 = '    SELECT THE LOCATORS THAT COINCIDE THE MIN CONTROLS:-'
line3 = '    N.B. MAKE SURE THAT ALL MAIN CONTROLS AXIS MATCH LOCATOR AXIS'
ver = ' : ver 01.003 : Groups all Locators'
windowTitle = 'Set Up Wing Flex' + ver
rebuildCurveWindowName = 'SetUpWingFlex'
deleteWindow(rebuildCurveWindowName)
buildWindow(rebuildCurveWindowName,windowTitle,line1,line2,line3)


Python: Maya: Set Up IKFK Visibility Switch

# USE : 
# REQUIRES:
#    1. checkAttrExist
#    2. editTxtGrpButtonArray
#    3. deleteWindow()
#    5. setUpIKFKparent
#    6. setColour
#    7. getShapeNodes
#    8. setUpIKFKswitch

# NOTES : 
#    1. SELECT JOINTS
#    2. SELECT IK CONTROL OBJECTS
#    3. SELECT FK CONTROL OBJECTS
#    4. TYPE OR SELECT THE NAME OF THE IKFK SWITCH CONTROL
#    5. SELECT CONTRAINT TYPE
#    6. TYPE THE PREFIX NAME
#    7. TYPE THE NAME OF TYPE OF JOINT

def setUpIkFfVisibilitySwitch(prefix,ikArray,fkArray,ctrl,attribute,setRange):
    checkAttrExist(ctrl,attribute,'double',0,10,0,True,False)
    ikFkSwitchSetRange = prefix + 'ikFk_vis_switch_setRange'
    setRangeNode = setRange

    source = ctrl + '.' + attribute

    if(maya.cmds.objExists(setRange) == False):
        setRangeNode = maya.cmds.shadingNode('setRange',n=prefix + 'IKFK_setRange',au=True)

    source = setRangeNode + '.outValueX'
    print('setUpIkFfVisibilitySwitch :: ikArray = ' + str(ikArray))

    if(len(ikArray) > 0):
        print('setUpIkFfVisibilitySwitch :: ik ')
        for c in ikArray:
            if maya.cmds.objExists(c):
                print('setUpIkFfVisibilitySwitch :: ik : c = ' + str(c))
                destination = c + '.visibility'
                maya.cmds.connectAttr(source, destination, force=True)

    source = setRangeNode + '.outValueY'

    if(len(fkArray) > 0):
        print('setUpIkFfVisibilitySwitch :: fk ')
        for c in fkArray:
            if maya.cmds.objExists(c):
                print('setUpIkFfVisibilitySwitch :: fk : c = ' + str(c))
                destination = c + '.visibility'
                maya.cmds.connectAttr(source, destination, force=True)

    print('setUpIkFfVisibilitySwitch :: setRangeNode = ' + str(setRangeNode))
    return setRangeNode
    
###############################################################################################
#     GUI:    
###############################################################################################

def buildWindow(windowName, windowTitle, line0, line1, line2, line3, line4, line5, line6):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 600))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')

    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.text( label= line5 )
    maya.cmds.textFieldGrp( windowName + '_prefix', label='Type Prefix:', text='L', en=True )
    maya.cmds.text( label= line6 )
    maya.cmds.textFieldGrp( windowName + '_limbType', label='Type Prefix:', text='leg', en=True )
    maya.cmds.text( label= line0 )
    maya.cmds.textFieldButtonGrp( windowName + '_joints', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_joints' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldButtonGrp( windowName + '_ikControls', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ikControls' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line2 )
    maya.cmds.textFieldButtonGrp( windowName + '_fkControls', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_fkControls' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line3 )
    maya.cmds.textFieldButtonGrp( windowName + '_ikfkControl', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ikfkControl' + '","textFieldButtonGrp")' )
    maya.cmds.textFieldGrp( windowName + '_attribute', label='Type Attribute Name:', text='IkFk', en=True )
    maya.cmds.text( label= line4)
    maya.cmds.radioButtonGrp( windowName + '_constraintType', label='Constraint Type:', labelArray3=['parent', 'point', 'aim'], numberOfRadioButtons=3, en=True, sl=1 )
    maya.cmds.text( label= '' )
    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):

    getPrefix = maya.cmds.textFieldGrp( windowName + '_prefix', q=True, text=True )
    p = getPrefix.split()
    SidePrefix = p[0] + '_'

    getLimbType = maya.cmds.textFieldGrp( windowName + '_limbType', q=True, text=True )
    lt  = getLimbType.split()
    limbTypeName = lt[0] + '_'

    getIk = maya.cmds.textFieldButtonGrp( windowName + '_ikControls', q=True, text=True )
    ikCTRLArray = getIk.split()

    getFk = maya.cmds.textFieldButtonGrp( windowName + '_fkControls', q=True, text=True )
    fkCTRLArray = getFk.split()

    getJoints = maya.cmds.textFieldButtonGrp( windowName + '_joints', q=True, text=True )
    joints = getJoints.split()

    getIKFKcontrol = maya.cmds.textFieldButtonGrp( windowName + '_ikfkControl', q=True, text=True )
    sc = getIKFKcontrol.split()
    ikfkSwitchCTRL = sc[0]
    print('ikfkSwitchCTRL = ' + ikfkSwitchCTRL)

    getIKFKattr = maya.cmds.textFieldGrp( windowName + '_attribute', q=True, text=True )
    attr = getIKFKattr.split()
    ikFkAttr = attr[0]

    ct = maya.cmds.radioButtonGrp( windowName + '_constraintType', q=True, sl=True )
    contraintType = whichConstaintType(ct)

    ikFkConsrtaintArray = []

    #CREATE AND SETUP CONTRAINTS
    for i in range(0,len(joints),1):
        #CHECK FOR AND DELETE EXISTING CONSTRAINT (NEED TO IMPLEMENT)
        
        ikFkConstraint = setUpIKFKparent(ikCTRLArray[i], fkCTRLArray[i], joints[i], contraintType, True, None)
        ikFkConsrtaintArray.append(ikFkConstraint)

    #SHOW AND UNLOCK ATTRIBUTES
    ikExist = False
    if(ikCTRLArray > 0):
        ikExist =True
    fkExist = False
    if(fkCTRLArray > 0):
        fkExist =True
    
    setRangeNode = setUpIKFKswitch(SidePrefix + limbTypeName,ikFkAttr,ikFkConsrtaintArray,ikfkSwitchCTRL,ikExist,fkExist)
    #HIDE AND LOCK ATTRIBUTES
    #lockHideAttr(ikfkSwitchCTRL,['tx','ty','tz','rx','ry','rz','sx','sy','sz'],True,False)
    #SET VISIBILITY SWITCH FOR CONTROL OBJECTS
    #note: THIS FUNCTION CATERS FOR NOT HAVING A SETRANGE NODE NOT PREVIOUSLY MADE
    setUpIkFfVisibilitySwitch(SidePrefix + limbTypeName,ikCTRLArray,fkCTRLArray,ikfkSwitchCTRL,ikFkAttr,setRangeNode)

    shape = getShapeNodes(ikCTRLArray[0])[0]
    print('shape = ' + str(shape))

    setColour([ikfkSwitchCTRL],clothColour[0])
    
    if(shape != None):
        setColour(ikCTRLArray,ikctrlColour)
        setColour(fkCTRLArray,fkctrlColour)

line0 = '    SELECT JOINTS :-'
line1 = '    SELECT IK CONTROL OBJECTS :-'
line2 = '    SELECT FK CONTROL OBJECTS :-'
line3 = '    TYPE OR SELECT THE NAME OF THE IKFK SWITCH CONTROL :-'
line4 = '    SELECT CONTRAINT TYPE :-'
line5 = '    TYPE THE PREFIX NAME:-'
line6 = '    TYPE THE NAME OF TYPE OF JOINT:-'


#0=Right, 1=Left, 2=Centre, 3=Misc
IKcolour = [14,13,17]
FKColour = [23,31,25]
splineIKColour = [6,15,29]#[17,21,23]
clothColour = [9,30,21]
faceColour = [22,10,26]
misc = [4,7,11]

SplnCtrlColour = splineIKColour[0]
ikctrlColour = IKcolour[0]
fkctrlColour = FKColour[0]

ver = ' : ver 01.005'
windowTitle = 'Set Up IkFk control Switch' + ver
rebuildCurveWindowName = 'setUpIkFkControlSwitch'
deleteWindow(rebuildCurveWindowName)
buildWindow(rebuildCurveWindowName, windowTitle, line0, line1, line2, line3, line4, line5, line6)

Python: Set Up IKFK Visibility Switch v2
Submitted by admin on Wed, 10/22/2014 - 05:45
# USE : 
# REQUIRES:
#    1. whichAxis()
#    2. editTxtGrpButtonArray
#    3. deleteWindow()
# NOTES : 
#     1. SELECT IK CONTROL OBJECTS
#    2. SELECT FK CONTROL OBJECTS
#    3. TYPE THE NAME OF THE IKFK SWITCH ATTRIBUTE
#    4. SELECT IKFK SWITCH CONTROL
#    5. SELECT OR TYPE EXISTING IKFK SETRANGE NODE (optional)

def setUpIkFfVisibilitySwitch2(prefix,ikArray,fkArray,ctrl,attribute):
    checkAttrExist(ctrl,attribute,'double',0,10,0,True,False)
    newSetRangeName = prefix + 'IKFK_switch_setRange'#'IKFK_vis_switch_setRange'
    setRangeNode = ''
    setRangeName = prefix + 'IKFK_setRange'# e.g. L_arm_IKFK_setRange

    source = ctrl + '.' + attribute

    if maya.cmds.objExists(setRangeName):
        setRangeNode = setRangeName
    else:
        setRangeNode = maya.cmds.shadingNode('setRange',n=setRangeName,au=True)
        maya.cmds.setAttr(setRangeNode + '.oldMinX',0)
        maya.cmds.setAttr(setRangeNode + '.oldMinY',0)
        maya.cmds.setAttr(setRangeNode + '.oldMaxX',10)
        maya.cmds.setAttr(setRangeNode + '.oldMaxY',10)
        maya.cmds.setAttr(setRangeNode + '.minX',1)
        maya.cmds.setAttr(setRangeNode + '.minY',0)
        maya.cmds.setAttr(setRangeNode + '.maxX',0)
        maya.cmds.setAttr(setRangeNode + '.maxY',1)
            
        destination = setRangeNode + '.valueX'
        maya.cmds.connectAttr(source, destination, force=True)

        destination = setRangeNode + '.valueY'
        maya.cmds.connectAttr(source, destination, force=True)

    source = setRangeNode + '.outValueX'
    print('setUpIkFfVisibilitySwitch :: ikArray = ' + str(ikArray))

    print('setUpIkFfVisibilitySwitch :: ik ')
    for c in ikArray:
        if maya.cmds.objExists(c):
            print('setUpIkFfVisibilitySwitch :: ik : c = ' + str(c))
            destination = c + '.visibility'
            maya.cmds.connectAttr(source, destination, force=True)

    source = setRangeNode + '.outValueY'

    for c in fkArray:
        if maya.cmds.objExists(c):
            print('setUpIkFfVisibilitySwitch :: fk : c = ' + str(c))
            destination = c + '.visibility'
            maya.cmds.connectAttr(source, destination, force=True)

    print('setUpIkFfVisibilitySwitch :: setRangeNode = ' + str(setRangeNode))
    return setRangeNode
    
###############################################################################################
#     GUI:    
###############################################################################################

def buildWindow(windowName, windowTitle, line1, line2, line3, line4, line5):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 300))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')

    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.textFieldGrp( windowName + '_prefix', label='Type Prefix:', text='L_leg_', en=True )
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldButtonGrp( windowName + '_ikControls', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ikControls' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line2 )
    maya.cmds.textFieldButtonGrp( windowName + '_fkControls', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_fkControls' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line3 )
    maya.cmds.textFieldGrp( windowName + '_attr', label='Type Attribute:', text='IkFk', en=True )
    maya.cmds.text( label= line4 )
    maya.cmds.textFieldButtonGrp( windowName + '_ikFkSwitch', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ikFkSwitch' + '","textFieldButtonGrp")' )

    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):
    getIk = maya.cmds.textFieldButtonGrp( windowName + '_ikControls', q=True, text=True )
    ikCTRLArray = getIk.split()

    getFk = maya.cmds.textFieldButtonGrp( windowName + '_fkControls', q=True, text=True )
    fkCTRLArray = getFk.split()


    getPrefix = maya.cmds.textFieldGrp( windowName + '_prefix', q=True, text=True )
    p = getPrefix.split()
    prefix = p[0]


    getAttr = maya.cmds.textFieldGrp( windowName + '_attr', q=True, text=True )
    a = getAttr.split()
    attr = ''
    print ('a = ' + str(a))
    print ('len(a) = ' + str(len(a)))
    if(len(a) < 1):
        attr = 'IKFK'
    else:
        attr = a[0]

    getIkfkSwitch = maya.cmds.textFieldButtonGrp( windowName + '_ikFkSwitch', q=True, text=True )
    ikfkSwitchCTRL = getIkfkSwitch.split()
    existIkFkSwitchSetRange = ''
    print ('ikfkSwitchCTRL = ' + str(ikfkSwitchCTRL))

    print ('fkCTRLArray = ' + str(fkCTRLArray))
    setUpIkFfVisibilitySwitch2(prefix,ikCTRLArray,fkCTRLArray,ikfkSwitchCTRL[0],attr)


line1 = '    SELECT IK CONTROL OBJECTS :-'
line2 = '    SELECT FK CONTROL OBJECTS :-'
line3 = '    TYPE THE NAME OF THE IKFK SWITCH ATTRIBUTE :-'
line4 = '    SELECT IKFK SWITCH CONTROL :-'
line5 = '    SELECT OR TYPE EXISTING IKFK SETRANGE NODE (optional):-'

ver = ' : ver 01.002'
windowTitle = 'Set Up IkFk Visibility Switch' + ver
rebuildCurveWindowName = 'setUpIkFkVisibilitySwitch'
deleteWindow(rebuildCurveWindowName)
buildWindow(rebuildCurveWindowName, windowTitle, line1, line2, line3, line4, line5)

Python: Set Up Shoulder Rig
Submitted by admin on Wed, 10/22/2014 - 05:55
# USE : 
# REQUIRES:
#    1. whichAxis()
#    2. editTxtGrpButtonArray
#    3. deleteWindow()
# NOTES : 
#    1. SELECT ALL THE JOINTS THAT MAKE UP THE IK JOINT CHAIN, IN ORDER, FROM START TO END
#    2. SELECT THE MAIN CTRL, THEN THE START CTRL, FINALLY THE END CTRL
#    3. SELECT OR TYPE IN HIERARCHICAL ORDER THE GROUP THAT THE DIMENSION NODE IS TO BE GROUPED UNDE

def setUpSplineIKstretch(jointArray,prefix,crve,aimAxis):
    splineNormaliseNode = prefix + 'spline_normalize_multiplyDivide'
    splineMultiplyNode = prefix + 'spline_multiplier_multiplyDivide'
    curveInfo = prefix + 'spline_curveInfo1'

    howManyJoints = len(jointArray)
    print ('howManyJoints = ' + str(howManyJoints))
    print ('howManyJoints / 3 = ' + str(float(howManyJoints) / float(3)))
    howManyNodes = int(math.ceil(float(howManyJoints) / float(3)))
    print ('howManyNodes = ' + str(howManyNodes))
    #START////////////////////////////////////////////////////////////////////////////////////CREATE CURVE INFO NODE FOR CHAR SPINE 
    #CREATE CURVE INFO AND MULTIPLYDIVIDE NODES
    curveInfoNode = maya.cmds.arclen(crve, ch=True)
    multiplierNode = maya.cmds.shadingNode('multiplyDivide',n=splineNormaliseNode + '1',au=True)

    splineNormalise = multiplierNode #ENSURE THAT THERE CONTINUITY THROUGH OUT THE SCRIPT

    #CONNECT ARCLENGTH TO INPUT1X 
    socket = multiplierNode + '.input1X'
    connector = curveInfoNode + '.arcLength'
    maya.cmds.connectAttr(connector, socket, force=True)

    #SET INPUT2X TO ARCLENGTH VALUE AND SET MULTIPLEDIVED NODES OPERATION TO DIVIDE
    socketAttribute = '.input2X'

    maya.cmds.setAttr(multiplierNode + '.operation',2)
    arcLength = maya.cmds.getAttr(connector)

    maya.cmds.setAttr(multiplierNode + '.input2X', arcLength)

    maya.cmds.rename(curveInfoNode, curveInfo)
    #print('splineMultiplyNode = ' + str(splineMultiplyNode))
    #END/////////////////////////////////////////////////////////////////////////////////////CREATE CURVE INFO NODE FOR CHAR SPINE 

    #START///////////////////////////////////////////////////////////////////////////////////CREATE MULTIPLYDIVIDE NODES TO BE CONNECTED TO THE INDIVIDUAL JOINTS TRANSLATEX 
        splineMultiply = []
        #CREATE MULTIPLYDIVIDE NODES 
        for i in range(0,howManyNodes,1):
        temp = maya.cmds.shadingNode('multiplyDivide', n=splineMultiplyNode + str(1), au=True)
        splineMultiply.append(temp)
        
    print ('splineMultiply = ' + str(splineMultiply))

    connectorAttribute1 = '.outputX' #change this variable
    socketAttribute1 = '.input' #change this variable
    connector1 = splineNormalise + connectorAttribute1
    connectorAttribute2 = '.output'
    
    whichJoint = 1

    whichAxis = [' ', 'X', 'Y', 'Z']
    brake = 0

    print ('jointArray 1 = ' + str(jointArray))

    #CONNECT THE NORMALISE NODE TO THE MULTIPLYDIVIDE NODES, COPY SPINE JOINT TRANSLATEX TO MULTIPLYDIVIDE NODES INPUT 1XYZ ATTRIBUTES AND 
    #CONNECT MULTIPLYDIVIDE NODES OUTPUT XYZ TO SPINE JOINT TRANSLATEX
    for i in range(0, howManyNodes, 1):
        
        #multiply = i + 1
    
        for j in range(1, 4, 1):
            if(brake == 0):
                
                #socket1 = splineMultiply + str(multiply) + (socketAttribute1 + '2' + whichAxis[j])
                socket1 = splineMultiply[i] + (socketAttribute1 + '2' + whichAxis[j])
                maya.cmds.connectAttr(connector1, socket1, force=True)
        
                getAttribute = maya.cmds.getAttr(jointArray[whichJoint] + '.t' + aimAxis.lower())
                #setAttr = maya.cmds.setAttr(splineMultiplyNode + str(multiply) + (socketAttribute1 + '1' + whichAxis[j]), getAttr)
                setAttr = maya.cmds.setAttr( splineMultiply[i] + (socketAttribute1 + '1' + whichAxis[j]), getAttribute)
        
                connector2 = splineMultiply[i] + (connectorAttribute2 + whichAxis[j])
                print ('connector2 = ' + str(connector2))
                socket2 = (jointArray[whichJoint] + '.t' + aimAxis.lower())
                print ('socket2 = ' + str(socket2))
                maya.cmds.connectAttr(connector2, socket2, force=True)

                whichJoint = whichJoint + 1
    
                print ('whichJoint = ' + str(whichJoint))
                print ('howManyJoints = ' + str(howManyJoints))

                #LOOP BREAK TO CATER FOR ODD NUMBER OF JOINTS
                if(whichJoint == howManyJoints):
                    brake = 1
                    print ('brake = ' + str(brake))

    #END/////////////////////////////////////////////////////////////////////////////////////CREATE MULTIPLYDIVIDE NODES TO BE CONNECTED TO THE INDIVIDUAL JOINTS TRANSLATEX 
    
###############################################################################################
#     NO GUI:    
###############################################################################################

def buildWindow(windowName,windowTitle, line1,line2,line3):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 300))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')
    #form = maya.cmds.formLayout(windowName + '_form1')
    #tabs = maya.cmds.tabLayout(windowName + '_tabs1', innerMarginWidth=5, innerMarginHeight=5)
    #maya.cmds.formLayout( form, edit=True, attachForm=[(tabs, 'top', 0), (tabs, 'left', 0), (tabs, 'bottom', 0), (tabs, 'right', 0)] )
    
    #maya.cmds.columnLayout('')
    #maya.cmds.scrollLayout('Global' , width=500, height=300, horizontalScrollBarThickness=16, verticalScrollBarThickness=16)

    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.textFieldGrp( windowName + '_sidePrefix', label='Side Prefix:', text='L', en=True )
    maya.cmds.textFieldGrp( windowName + '_jointType', label='joint type:', text='IK', en=True )
    maya.cmds.textFieldGrp( windowName + '_limbTypeName', label='Limb Type Name:', text='leg', en=True )
    maya.cmds.radioButtonGrp( windowName + '_jointAimAxis', label='Joint Aim Axis:', labelArray3=['X', 'Y', 'Z'], numberOfRadioButtons=3, en=True, sl=1 )
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldButtonGrp( windowName + '_joints', label='Get Joints:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_joints' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line2 )
    maya.cmds.textFieldButtonGrp( windowName + '_curve', label='Get SplineIK Curve:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_curve' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line3 )
    maya.cmds.textFieldButtonGrp( windowName + '_grp', label='Get Group:', text='char_GRP  DO_NOT_ALTER_GRP   curves_GRP', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_grp' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= '' )
    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.button(label='?', height = questionButtonHeight)
    maya.cmds.text( label= '   ' )
    maya.cmds.button(label='?', height = questionButtonHeight)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):
    sidePrefix = maya.cmds.textFieldGrp( windowName + '_sidePrefix', q=True, text=True )
    jointType = maya.cmds.textFieldGrp( windowName + '_jointType', q=True, text=True )
    limbTypeName = maya.cmds.textFieldGrp( windowName + '_limbTypeName', q=True, text=True )
    jaa = maya.cmds.radioButtonGrp( windowName + '_jointAimAxis', q=True, sl=True )
    jointAimAxis = whichAxis(jaa)[1]
    getCurve = maya.cmds.textFieldButtonGrp( windowName + '_curve', q=True, text=True )
    splineIkCurve = getCurve.split()[0]
    getJoints = maya.cmds.textFieldButtonGrp( windowName + '_joints', q=True, text=True )
    joints = getJoints.split()
    getGroup = maya.cmds.textFieldButtonGrp( windowName + '_grp', q=True, text=True )
    groupCurve = getGroup.split()

    sidePrefix = sidePrefix + '_'
    jointType = jointType + '_'
    limbTypeName = limbTypeName + '_'
    prefix = sidePrefix + jointType + limbTypeName

    howManyNodes = int(math.ceil(len(joints) / 3)) #This divided by three because of X,Y,Z

    setUpGrp(groupCurve)
    print ('joints[0:(len(joints)-1)] = ' + str(joints[0:(len(joints)-1)]))

    splineIKstretchjoints = setUpSplineIKstretch(joints[0:(len(joints)-1)],prefix,splineIkCurve,jointAimAxis)
    
    



line1 = '    SELECT ALL THE JOINTS THAT MAKE UP THE IK JOINT CHAIN, IN ORDER, FROM START TO END:-'
line2 = '    SELECT THE MAIN CTRL, THEN THE START CTRL, FINALLY THE END CTRL:-'
line3 = '    SELECT OR TYPE IN HIERARCHICAL ORDER THE GROUP THAT THE DIMENSION NODE IS TO BE GROUPED UNDER'
ver = ' : ver 01.001 : '
windowTitle = 'Set Up Spline IK Stretch' + ver
rebuildCurveWindowName = 'SetUpSplineIKstretch'
deleteWindow(rebuildCurveWindowName)
buildWindow(rebuildCurveWindowName,windowTitle,line1,line2,line3)

Python: Set Up Spline Visibility Scale
Submitted by admin on Wed, 10/22/2014 - 05:59
# USE : 
# REQUIRES:
#    1. editTxtGrpButtonArray
#    2. deleteWindow()
# NOTES : 
# 1. SELECT IK CONTROL OBJECTS
# 2. SELECT FK CONTROL OBJECTS
# 3. TYPE THE NAME OF THE SPLINE IK CTRL SCALE ATTRIBUTE
# 4. TYPE THE NAME OF THE SPLINE IK CTRL VISIBILITY ATTRIBUTE 
# 5. SELECT OR TYPE EXISTING IKFK SETRANGE NODE (optional)

def setUpSplineVisScale(prefix,objArray,ctrl,scaleAttr,visAttr):
    checkAttrExist(ctrl,visAttr,'long',0,1,1,True,False)
    checkAttrExist(ctrl,scaleAttr,'double',0,100,1,False,False)

    source1 = ctrl + '.' + scaleAttr
    source2 = ctrl + '.' + visAttr

    for c in objArray:
        if maya.cmds.objExists(c):
            print('setUpSplineVisScale :: c = ' + str(c))
            destination = c + '.sx'
            maya.cmds.connectAttr(source1, destination, force=True)
            destination = c + '.sy'
            maya.cmds.connectAttr(source1, destination, force=True)
            destination = c + '.sz'
            maya.cmds.connectAttr(source1, destination, force=True)

            destination = c + '.visibility'
            maya.cmds.connectAttr(source2, destination, force=True)
    
###############################################################################################
#     GUI:    
###############################################################################################

def buildWindow(windowName, windowTitle, line1, line2, line3, line4, line5):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 300))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')
    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.textFieldGrp( windowName + '_prefix', label='Type Prefix:', text='L_leg_', en=True )
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldButtonGrp( windowName + '_ctrl', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ctrl' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line3 )
    maya.cmds.textFieldGrp( windowName + '_scaleAttr', label='Type Attribute:', text='scaleSpline', en=True )
    maya.cmds.text( label= line4 )
    maya.cmds.textFieldGrp( windowName + '_visAttr', label='Type Attribute:', text='spline', en=True )
    maya.cmds.text( label= line4 )
    maya.cmds.textFieldButtonGrp( windowName + '_ikFkSwitch', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ikFkSwitch' + '","textFieldButtonGrp")' )
    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):

    getCtrl = maya.cmds.textFieldButtonGrp( windowName + '_ctrl', q=True, text=True )
    ctrlArray = getCtrl.split()

    getPrefix = maya.cmds.textFieldGrp( windowName + '_prefix', q=True, text=True )
    p = getPrefix.split()
    prefix = p[0]

    getVisAttr = maya.cmds.textFieldGrp( windowName + '_visAttr', q=True, text=True )
    a = getVisAttr.split()
    visAttr = ''
    print ('a = ' + str(a))
    print ('len(a) = ' + str(len(a)))
    if(len(a) < 1):
        visAttr = 'spline'
    else:
        visAttr = a[0]

    getScaleAttr = maya.cmds.textFieldGrp( windowName + '_scaleAttr', q=True, text=True )
    s = getScaleAttr.split()
    scaleAttr = ''
    print ('s = ' + str(s))
    print ('len(s) = ' + str(len(s)))
    if(len(s) < 1):
        scaleAttr = 'scaleSpline'
    else:
        scaleAttr = s[0]

    getIkfkSwitch = maya.cmds.textFieldButtonGrp( windowName + '_ikFkSwitch', q=True, text=True )
    ikfkSwitchCTRL = getIkfkSwitch.split()[0]
    existIkFkSwitchSetRange = ''
    print ('ikfkSwitchCTRL = ' + str(ikfkSwitchCTRL))

    setUpSplineVisScale(prefix,ctrlArray,ikfkSwitchCTRL,scaleAttr,visAttr)


line1 = '    SELECT IK CONTROL OBJECTS :-'
line2 = '    SELECT FK CONTROL OBJECTS :-'
line3 = '    TYPE THE NAME OF THE SPLINE IK CTRL SCALE ATTRIBUTE :-'
line4 = '    TYPE THE NAME OF THE SPLINE IK CTRL VISIBILITY ATTRIBUTE :-'
line5 = '    SELECT OR TYPE EXISTING IKFK SETRANGE NODE (optional):-'

windowTitle = 'Set Up Spline IK Ctrl Visibility Scale Switch'
rebuildCurveWindowName = 'setUpSplineIKCtrlVisibilityScaleSwitch'
deleteWindow(rebuildCurveWindowName)
buildWindow(rebuildCurveWindowName, windowTitle, line1, line2, line3, line4, line5)


Python: Maya: Set Up IKFK Parent Constraint with Roll

# USE : 
# REQUIRES:
#    1. checkAttrExist
#    1. whichAxis()
#    2. editTxtGrpButtonArray
#    3. deleteWindow()
#    4. createRoll2
#    5. setUpIKFKparent
#    6. setColour
#    7. getShapeNodes
#    8. setUpIKFKswitch
#    9. connectRoll
#    10. connectRoll2
# NOTES : 
#    1. TYPE THE PREFIX NAME
#    2. TYPE THE NAME OF TYPE OF JOINT
#    3. SELECT DEFORMER OBJECTS FROM END OF IK CHAIN TO START
#    4. SELECT IK CONTROL OBJECTS FROM END OF IK CHAIN TO START
#    5. SELECT FK CONTROL OBJECTS FROM END OF FK CHAIN TO START
#    6. TYPE OR SELECT THE NAME OF THE IKFK SWITCH CONTROL
#    7. TYPE OR SELECT THE NAME OF THE CONTROL THAT DRIVES ROLL
#    8. SELECT TYPE OF CONSTRAINT


    
###############################################################################################
#     GUI:    
###############################################################################################

def buildWindow(windowName, windowTitle, line0, line1, line2, line3, line4, line5, line6):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 600))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')

    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.text( label= line0 )
    maya.cmds.textFieldGrp( windowName + '_prefix', label='Type Prefix:', text='L', en=True )
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldGrp( windowName + '_limbType', label='Type Prefix:', text='leg', en=True )
    maya.cmds.radioButtonGrp( windowName + '_jointAimAxis', label='Joint Aim Axis:', labelArray3=['X', 'Y', 'Z'], numberOfRadioButtons=3, en=True, sl=1 )
    maya.cmds.radioButtonGrp( windowName + '_controlAimAxis', label='Control Aim Axis:', labelArray3=['X', 'Y', 'Z'], numberOfRadioButtons=3, en=True, sl=1 )
    maya.cmds.text( label= line2 )
    maya.cmds.textFieldButtonGrp( windowName + '_joints', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_joints' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line3 )
    maya.cmds.textFieldButtonGrp( windowName + '_ikControls', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ikControls' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line4 )
    maya.cmds.textFieldButtonGrp( windowName + '_fkControls', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_fkControls' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line5 )
    maya.cmds.textFieldButtonGrp( windowName + '_ikfkControl', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ikfkControl' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line6 )
    maya.cmds.textFieldButtonGrp( windowName + '_twistControl', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_twistControl' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line7)
    maya.cmds.radioButtonGrp( windowName + '_constraintType', label='Constraint Type:', labelArray3=['parent', 'point', 'aim'], numberOfRadioButtons=3, en=True, sl=1 )
    maya.cmds.checkBoxGrp(windowName + '_createRoll', numberOfCheckBoxes=1, label='Create Roll', value1=True)
    maya.cmds.checkBoxGrp(windowName + '_invert', numberOfCheckBoxes=1, label='Invert Roll', value1=False)
    maya.cmds.text( label= '' )
    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):

    getPrefix = maya.cmds.textFieldGrp( windowName + '_prefix', q=True, text=True )
    p = getPrefix.split()
    SidePrefix = p[0] + '_'

    getLimbType = maya.cmds.textFieldGrp( windowName + '_limbType', q=True, text=True )
    lt  = getLimbType.split()
    limbTypeName = lt[0] + '_'

    getIk = maya.cmds.textFieldButtonGrp( windowName + '_ikControls', q=True, text=True )
    ikCTRLArray = getIk.split()

    getFk = maya.cmds.textFieldButtonGrp( windowName + '_fkControls', q=True, text=True )
    fkCTRLArray = getFk.split()

    getJoints = maya.cmds.textFieldButtonGrp( windowName + '_joints', q=True, text=True )
    joints = getJoints.split()

    jaa = maya.cmds.radioButtonGrp( windowName + '_jointAimAxis', q=True, sl=True )
    jointAimAxis = whichAxis(jaa)[1]

    caa = maya.cmds.radioButtonGrp( windowName + '_controlAimAxis', q=True, sl=True )
    controlAimAxis = whichAxis(caa)[1]

    getIKFKcontrol = maya.cmds.textFieldButtonGrp( windowName + '_ikfkControl', q=True, text=True )
    sc = getIKFKcontrol.split()
    ikfkSwitchCTRL = sc[0]
    print('ikfkSwitchCTRL = ' + ikfkSwitchCTRL)

    getMainCtrl = maya.cmds.textFieldButtonGrp( windowName + '_twistControl', q=True, text=True )
    mainCtrl = getMainCtrl.split()[0]

    ct = maya.cmds.radioButtonGrp( windowName + '_constraintType', q=True, sl=True )
    contraintType = whichConstaintType(ct)

    createRoll = maya.cmds.checkBoxGrp(windowName + '_createRoll', q=True, value1=True)
    invert = maya.cmds.checkBoxGrp(windowName + '_invert', q=True, value1=True)

    ikFkConsrtaintArray = []
    ikRollGroup = []
    fkRollGroup = []

    prefix = SidePrefix + limbTypeName 

    howManyNodes = int(math.ceil(len(joints) / 3)) #This divided by three because of X,Y,Z

    ikExist = False
    if(len(ikCTRLArray) > 0):
        ikExist =True
    fkExist = False
    if(len(fkCTRLArray) > 0):
        fkExist =True

    print('fkExist = ' + str(fkExist))
    print('len(fkCTRLArray) = ' + str(len(fkCTRLArray)))
    if(createRoll == True):
        if(ikExist == True):
            if(limbTypeName == 'arm_'):
                ikRollGroup = createRoll2(prefix,ikCTRLArray,120,[[0.0,0.0,3],[1.0,1.0,3],[0.5,0.12,3],[0.8,0.380,3]],jointAimAxis,controlAimAxis,mainCtrl,invert)
            if(limbTypeName == 'leg_'):
                ikRollGroup = createRoll2(prefix,ikCTRLArray,30,[[1.0,0.0,3],[0.0,1.0,3],[0.5,0.6,3]],jointAimAxis,controlAimAxis,mainCtrl,invert)
            if(fkExist == True):
                if(limbTypeName == 'arm_'):
                    fkRollGroup = connectRoll(ikRollGroup[0],fkCTRLArray,jointAimAxis)
                if(limbTypeName == 'leg_'):
                    fkRollGroup = connectRoll(ikRollGroup[0],fkCTRLArray,jointAimAxis)
                #INCLUDE IK AND FK ARRAYS
                for i in range(0,len(joints),1):
                    print('ikRollGroup = ' + str(ikRollGroup))
                    print('fkRollGroup = ' + str(fkRollGroup))
                    print('joints = ' + str(joints))
                    ikFkConstraint = setUpIKFKparent(ikRollGroup[1][i], fkRollGroup[i], joints[i], contraintType, True, None)
                    ikFkConsrtaintArray.append(ikFkConstraint)
            else:
                #INCLUDE IK ARRAY ONLY
                for i in range(0,len(joints),1):
                    ikFkConstraint = setUpIKFKparent(ikRollGroup[1][i], None, joints[i], contraintType, True, None)
                    ikFkConsrtaintArray.append(ikFkConstraint)

        elif(fkExist == True):
            if(limbTypeName == 'arm_'):
                fkRollGroup = createRoll2(prefix,fkCTRLArray,120,[[0.0,0.0,3],[1.0,1.0,3],[0.5,0.12,3],[0.8,0.380,3]],jointAimAxis,controlAimAxis,mainCtrl,invert)
            if(limbTypeName == 'leg_'):
                fkRollGroup = createRoll2(prefix,fkCTRLArray,30,[[1.0,0.0,3],[0.0,1.0,3],[0.5,0.6,3]],jointAimAxis,controlAimAxis,mainCtrl,invert)
            #INCLUDE FK ARRAY ONLY
            for i in range(0,len(joints),1):
                
                ikFkConstraint = setUpIKFKparent(None, fkRollGroup[1][i], joints[i], contraintType, True, None)
                ikFkConsrtaintArray.append(ikFkConstraint)

        else:
            print('ERROR :: ' + rebuildCurveWindowName + ' :: no IK or FK joints exist!!!!!!')

    else:
        for i in range(0,len(joints),1):
            ikFkConstraint = setUpIKFKparent(ikCTRLArray[i], fkCTRLArray[i], joints[i], contraintType, True, None)
            ikFkConsrtaintArray.append(ikFkConstraint)

    print('ikFkConsrtaintArray = ' + str(ikFkConsrtaintArray))
    setUpIKFKswitch(SidePrefix + limbTypeName,ikFkConsrtaintArray,ikfkSwitchCTRL,ikExist,fkExist)

    shape = getShapeNodes(ikCTRLArray[0])[0]
    print('shape = ' + str(shape))

    setColour([ikfkSwitchCTRL],clothColour[0])
    
    if(shape != None):
        setColour(ikCTRLArray,ikctrlColour)
        setColour(fkCTRLArray,fkctrlColour)

line0 = '    TYPE THE PREFIX NAME:- '
line1 = '    TYPE THE NAME OF TYPE OF JOINT :-'
line2 = '    SELECT DEFORMER OBJECTS FROM END OF IK CHAIN TO START :-'
line3 = '    SELECT IK CONTROL OBJECTS FROM END OF IK CHAIN TO START :- '
line4 = '    SELECT FK CONTROL OBJECTS FROM END OF FK CHAIN TO START :-'
line5 = '    TYPE OR SELECT THE NAME OF THE IKFK SWITCH CONTROL :-'
line6 = '    TYPE OR SELECT THE NAME OF THE CONTROL THAT DRIVES ROLL :-'
line7 = '    SELECT TYPE OF CONSTRAINT :-'


#0=Right, 1=Left, 2=Centre, 3=Misc
IKcolour = [14,13,17]
FKColour = [23,31,25]
splineIKColour = [6,15,29]#[17,21,23]
clothColour = [9,30,21]
faceColour = [22,10,26]
misc = [4,7,11]

SplnCtrlColour = splineIKColour[0]
ikctrlColour = IKcolour[0]
fkctrlColour = FKColour[0]

ver = ' : ver 01.004'
windowTitle = 'Set Up IkFk control Switch with Roll' + ver
rebuildCurveWindowName = 'setUpIkFkControlSwitchWithRoll'
deleteWindow(rebuildCurveWindowName)
buildWindow(rebuildCurveWindowName, windowTitle, line0, line1, line2, line3, line4, line5, line6)


Python: Maya: Set Up IK Stretch

You are here
Home » Programming » Maya Python Script Function Library
Maya Python Script Function Library
Python: Set Shape Node Visibility
Submitted by admin on Wed, 10/22/2014 - 05:41
import maya.cmds
import random
import math
# USE : 
# REQUIRES:
#    1. getShapeNodes()
# NOTES : 
#     1. SELECT IK CONTROL OBJECTS
#    2. SELECT FK CONTROL OBJECTS
#    3. TYPE THE NAME OF THE IKFK SWITCH ATTRIBUTE
#    4. SELECT IKFK SWITCH CONTROL
#    5. SELECT OR TYPE EXISTING IKFK SETRANGE NODE (optional)

def setUpIkFfVisibilitySwitch2(prefix,ikArray,fkArray,ctrl,attribute):
    checkAttrExist(ctrl,attribute,'double',0,10,0,True,False)
    newSetRangeName = prefix + 'IKFK_switch_setRange'#'IKFK_vis_switch_setRange'
    setRangeNode = ''
    setRangeName = prefix + 'IKFK_setRange'# e.g. L_arm_IKFK_setRange

    source = ctrl + '.' + attribute

    if maya.cmds.objExists(setRangeName):
        setRangeNode = setRangeName
    else:
        setRangeNode = maya.cmds.shadingNode('setRange',n=setRangeName,au=True)
        maya.cmds.setAttr(setRangeNode + '.oldMinX',0)
        maya.cmds.setAttr(setRangeNode + '.oldMinY',0)
        maya.cmds.setAttr(setRangeNode + '.oldMaxX',10)
        maya.cmds.setAttr(setRangeNode + '.oldMaxY',10)
        maya.cmds.setAttr(setRangeNode + '.minX',1)
        maya.cmds.setAttr(setRangeNode + '.minY',0)
        maya.cmds.setAttr(setRangeNode + '.maxX',0)
        maya.cmds.setAttr(setRangeNode + '.maxY',1)
            
        destination = setRangeNode + '.valueX'
        maya.cmds.connectAttr(source, destination, force=True)

        destination = setRangeNode + '.valueY'
        maya.cmds.connectAttr(source, destination, force=True)

    source = setRangeNode + '.outValueX'
    print('setUpIkFfVisibilitySwitch :: ikArray = ' + str(ikArray))

    print('setUpIkFfVisibilitySwitch :: ik ')
    for c in ikArray:
        if maya.cmds.objExists(c):
            print('setUpIkFfVisibilitySwitch :: ik : c = ' + str(c))
            destination = c + '.visibility'
            maya.cmds.connectAttr(source, destination, force=True)

    source = setRangeNode + '.outValueY'

    for c in fkArray:
        if maya.cmds.objExists(c):
            print('setUpIkFfVisibilitySwitch :: fk : c = ' + str(c))
            destination = c + '.visibility'
            maya.cmds.connectAttr(source, destination, force=True)

    print('setUpIkFfVisibilitySwitch :: setRangeNode = ' + str(setRangeNode))
    return setRangeNode
    
###############################################################################################
#    NO GUI:    
###############################################################################################

#0=Right, 1=Left, 2=Centre, 3=Misc
IKcolour = [14,13,17]
FKColour = [23,31,25]
splineIKColour = [6,15,29]#[17,21,23]
clothColour = [9,30,21]
faceColour = [22,10,26]
misc = [4,7,11]

SplnCtrlColour = splineIKColour[0]
ikctrlColour = IKcolour[0]
fkctrlColour = FKColour[0]

sel = maya.cmds.ls(selection=True)
sidePrefix = 'L_'
jointType = 'IK_'
vis = False


if(sidePrefix == 'L_'):
    SplnCtrlColour = splineIKColour[0]
    ikctrlColour = IKcolour[0]
    fkctrlColour = FKColour[0]
elif(sidePrefix == 'R_'):
    SplnCtrlColour = splineIKColour[1]
    ikctrlColour = IKcolour[1]
    fkctrlColour = FKColour[1]
else:
    SplnCtrlColour = splineIKColour[2]
    ikctrlColour = IKcolour[2]
    fkctrlColour = FKColour[2]


for i in sel:
    shape = getShapeNodes(i)[0][0]
    maya.cmds.setAttr(shape + '.visibility', False)

Python: Set Up Control Isolation
Submitted by admin on Wed, 10/22/2014 - 05:42
# USE : 
# REQUIRES:
#    1. checkAttrExist
#    2. editTxtGrpButtonArray
#    3. deleteWindow()

# NOTES : 
#    1. SELECT CONTROL OBJECTS
#    2. SELECT PARENT OBJECTS

def setUpControlIsolation(cntrl,parentObj,cntrlGrpName):
    grp = ''
    attrName = 'isolate'
    getParent = maya.cmds.listRelatives(cntrl,p=True,typ='transform')
    if(getParent != None):
        if(len(getParent) == 1):
            if(getParent[0] == cntrlGrpName):
                grp = cntrlGrpName
            else:
                grp = maya.cmds.group(em=True,n=cntrlGrpName)
                maya.cmds.parent(grp,getParent[0],r=True)
                maya.cmds.parent(cntrl,grp,r=True)
                print grp

    else:
        grp = maya.cmds.group(em=True,n=cntrlGrpName)
        maya.cmds.parent(cntrl,grp,r=True)
        print grp

    setRangeNode = cntrl + 'isolate_setRange'
    if(maya.cmds.objExists(setRangeNode) == False):
        setRangeNode = maya.cmds.shadingNode('setRange',n=cntrl + 'isolate_setRange',au=True)
    
###############################################################################################
#     GUI:    
###############################################################################################

def buildWindow(windowName, windowTitle, line1, line2):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 300))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')

    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldButtonGrp( windowName + '_ctrl', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ctrl' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line3 )
    maya.cmds.textFieldButtonGrp( windowName + '_parent', label='Type Attribute:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_parent' + '","textFieldButtonGrp")' )
    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):

    getCtrl = maya.cmds.textFieldButtonGrp( windowName + '_ctrl', q=True, text=True )
    ctrlArray = getCtrl.split()
    control = ctrlArray[0]

    getParent = maya.cmds.textFieldGrp( windowName + '_parent', q=True, text=True )
    p = getParent.split()
    parent = p[0]

    setUpControlIsolation(control,parent,control + '_GRP')




line1 = '    SELECT CONTROL OBJECTS :-'
line2 = '    SELECT PARENT OBJECTS :-'



windowTitle = 'Set Up Isolate Control'
rebuildCurveWindowName = 'setUpIsolateControl'
deleteWindow(rebuildCurveWindowName)
buildWindow(rebuildCurveWindowName, windowTitle, line1, line2)

Python: Set Up IK FK Visibility Switch
Submitted by admin on Tue, 10/21/2014 - 14:39
import maya.cmds
import random
import math
# USE : 
# REQUIRES:
#    1. getShapeNodes()
# NOTES : 
#     1. SELECT IK CONTROL OBJECTS
#    2. SELECT FK CONTROL OBJECTS
#    3. TYPE THE NAME OF THE IKFK SWITCH ATTRIBUTE
#    4. SELECT IKFK SWITCH CONTROL
#    5. SELECT OR TYPE EXISTING IKFK SETRANGE NODE (optional)

def setUpIkFfVisibilitySwitch2(prefix,ikArray,fkArray,ctrl,attribute):
    checkAttrExist(ctrl,attribute,'double',0,10,0,True,False)
    newSetRangeName = prefix + 'IKFK_switch_setRange'#'IKFK_vis_switch_setRange'
    setRangeNode = ''
    setRangeName = prefix + 'IKFK_setRange'# e.g. L_arm_IKFK_setRange

    source = ctrl + '.' + attribute

    if maya.cmds.objExists(setRangeName):
        setRangeNode = setRangeName
    else:
        setRangeNode = maya.cmds.shadingNode('setRange',n=setRangeName,au=True)
        maya.cmds.setAttr(setRangeNode + '.oldMinX',0)
        maya.cmds.setAttr(setRangeNode + '.oldMinY',0)
        maya.cmds.setAttr(setRangeNode + '.oldMaxX',10)
        maya.cmds.setAttr(setRangeNode + '.oldMaxY',10)
        maya.cmds.setAttr(setRangeNode + '.minX',1)
        maya.cmds.setAttr(setRangeNode + '.minY',0)
        maya.cmds.setAttr(setRangeNode + '.maxX',0)
        maya.cmds.setAttr(setRangeNode + '.maxY',1)
            
        destination = setRangeNode + '.valueX'
        maya.cmds.connectAttr(source, destination, force=True)

        destination = setRangeNode + '.valueY'
        maya.cmds.connectAttr(source, destination, force=True)

    source = setRangeNode + '.outValueX'
    print('setUpIkFfVisibilitySwitch :: ikArray = ' + str(ikArray))

    print('setUpIkFfVisibilitySwitch :: ik ')
    for c in ikArray:
        if maya.cmds.objExists(c):
            print('setUpIkFfVisibilitySwitch :: ik : c = ' + str(c))
            destination = c + '.visibility'
            maya.cmds.connectAttr(source, destination, force=True)

    source = setRangeNode + '.outValueY'

    for c in fkArray:
        if maya.cmds.objExists(c):
            print('setUpIkFfVisibilitySwitch :: fk : c = ' + str(c))
            destination = c + '.visibility'
            maya.cmds.connectAttr(source, destination, force=True)

    print('setUpIkFfVisibilitySwitch :: setRangeNode = ' + str(setRangeNode))
    return setRangeNode
    
###############################################################################################
#    NO GUI:    
###############################################################################################

#0=Right, 1=Left, 2=Centre, 3=Misc
IKcolour = [14,13,17]
FKColour = [23,31,25]
splineIKColour = [6,15,29]#[17,21,23]
clothColour = [9,30,21]
faceColour = [22,10,26]
misc = [4,7,11]

SplnCtrlColour = splineIKColour[0]
ikctrlColour = IKcolour[0]
fkctrlColour = FKColour[0]

sel = maya.cmds.ls(selection=True)
sidePrefix = 'L_'
jointType = 'IK_'
vis = False


if(sidePrefix == 'L_'):
    SplnCtrlColour = splineIKColour[0]
    ikctrlColour = IKcolour[0]
    fkctrlColour = FKColour[0]
elif(sidePrefix == 'R_'):
    SplnCtrlColour = splineIKColour[1]
    ikctrlColour = IKcolour[1]
    fkctrlColour = FKColour[1]
else:
    SplnCtrlColour = splineIKColour[2]
    ikctrlColour = IKcolour[2]
    fkctrlColour = FKColour[2]


for i in sel:
    shape = getShapeNodes(i)[0][0]
    maya.cmds.setAttr(shape + '.visibility', False)

Python: Set Up IK Spline IK Stretch
Submitted by admin on Wed, 10/22/2014 - 05:56
# USE : sets up spline IK to be able to stretch
# REQUIRES:
#    1. whichAxis(value)
#    2. editTxtGrpButtonArray
#    3. deleteWindow()
# NOTES : 
# 1. SELECT ALL THE JOINTS THAT MAKE UP THE IK JOINT CHAIN, IN ORDER, FROM START TO END
# 2. SELECT THE MAIN CTRL, THEN THE START CTRL, FINALLY THE END CTRL
# 3. SELECT OR TYPE IN HIERARCHICAL ORDER THE GROUP THAT THE DIMENSION NODE IS TO BE GROUPED UNDER

def setUpSplineIKstretch(jointArray,prefix,crve,aimAxis):
    splineNormaliseNode = prefix + 'spline_normalize_multiplyDivide'
    splineMultiplyNode = prefix + 'spline_multiplier_multiplyDivide'
    curveInfo = prefix + 'spline_curveInfo1'

    howManyJoints = len(jointArray)
    print ('howManyJoints = ' + str(howManyJoints))
    print ('howManyJoints / 3 = ' + str(float(howManyJoints) / float(3)))
    howManyNodes = int(math.ceil(float(howManyJoints) / float(3)))
    print ('howManyNodes = ' + str(howManyNodes))
    #START////////////////////////////////////////////////////////////////////////////////////CREATE CURVE INFO NODE FOR CHAR SPINE 
    #CREATE CURVE INFO AND MULTIPLYDIVIDE NODES
    curveInfoNode = maya.cmds.arclen(crve, ch=True)
    multiplierNode = maya.cmds.shadingNode('multiplyDivide',n=splineNormaliseNode + '1',au=True)

    splineNormalise = multiplierNode #ENSURE THAT THERE CONTINUITY THROUGH OUT THE SCRIPT

    #CONNECT ARCLENGTH TO INPUT1X 
    socket = multiplierNode + '.input1X'
    connector = curveInfoNode + '.arcLength'
    maya.cmds.connectAttr(connector, socket, force=True)

    #SET INPUT2X TO ARCLENGTH VALUE AND SET MULTIPLEDIVED NODES OPERATION TO DIVIDE
    socketAttribute = '.input2X'

    maya.cmds.setAttr(multiplierNode + '.operation',2)
    arcLength = maya.cmds.getAttr(connector)

    maya.cmds.setAttr(multiplierNode + '.input2X', arcLength)

    maya.cmds.rename(curveInfoNode, curveInfo)
    #print('splineMultiplyNode = ' + str(splineMultiplyNode))
    #END/////////////////////////////////////////////////////////////////////////////////////CREATE CURVE INFO NODE FOR CHAR SPINE 

    #START///////////////////////////////////////////////////////////////////////////////////CREATE MULTIPLYDIVIDE NODES TO BE CONNECTED TO THE INDIVIDUAL JOINTS TRANSLATEX 
        splineMultiply = []
        #CREATE MULTIPLYDIVIDE NODES 
        for i in range(0,howManyNodes,1):
        temp = maya.cmds.shadingNode('multiplyDivide', n=splineMultiplyNode + str(1), au=True)
        splineMultiply.append(temp)
        
    print ('splineMultiply = ' + str(splineMultiply))

    connectorAttribute1 = '.outputX' #change this variable
    socketAttribute1 = '.input' #change this variable
    connector1 = splineNormalise + connectorAttribute1
    connectorAttribute2 = '.output'
    
    whichJoint = 1

    whichAxis = [' ', 'X', 'Y', 'Z']
    brake = 0

    print ('jointArray 1 = ' + str(jointArray))

    #CONNECT THE NORMALISE NODE TO THE MULTIPLYDIVIDE NODES, COPY SPINE JOINT TRANSLATE-X TO MULTIPLYDIVIDE NODES INPUT 1XYZ ATTRIBUTES AND 
    #CONNECT MULTIPLYDIVIDE NODES OUTPUT XYZ TO SPINE JOINT TRANSLATEX
    for i in range(0, howManyNodes, 1):
        
        #multiply = i + 1
    
        for j in range(1, 4, 1):
            if(brake == 0):
                
                #socket1 = splineMultiply + str(multiply) + (socketAttribute1 + '2' + whichAxis[j])
                socket1 = splineMultiply[i] + (socketAttribute1 + '2' + whichAxis[j])
                maya.cmds.connectAttr(connector1, socket1, force=True)
        
                getAttribute = maya.cmds.getAttr(jointArray[whichJoint] + '.t' + aimAxis.lower())
                #setAttr = maya.cmds.setAttr(splineMultiplyNode + str(multiply) + (socketAttribute1 + '1' + whichAxis[j]), getAttr)
                setAttr = maya.cmds.setAttr( splineMultiply[i] + (socketAttribute1 + '1' + whichAxis[j]), getAttribute)
        
                connector2 = splineMultiply[i] + (connectorAttribute2 + whichAxis[j])
                print ('connector2 = ' + str(connector2))
                socket2 = (jointArray[whichJoint] + '.t' + aimAxis.lower())
                print ('socket2 = ' + str(socket2))
                maya.cmds.connectAttr(connector2, socket2, force=True)

                whichJoint = whichJoint + 1
    
                print ('whichJoint = ' + str(whichJoint))
                print ('howManyJoints = ' + str(howManyJoints))

                #LOOP BREAK TO CATER FOR ODD NUMBER OF JOINTS
                if(whichJoint == howManyJoints):
                    brake = 1
                    print ('brake = ' + str(brake))

    #END/////////////////////////////////////////////////////////////////////////////////////CREATE MULTIPLYDIVIDE NODES TO BE CONNECTED TO THE INDIVIDUAL JOINTS TRANSLATEX 
    
###############################################################################################
#     GUI:    
###############################################################################################

def buildWindow(windowName,windowTitle, line1,line2,line3):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 300))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')
    #form = maya.cmds.formLayout(windowName + '_form1')
    #tabs = maya.cmds.tabLayout(windowName + '_tabs1', innerMarginWidth=5, innerMarginHeight=5)
    #maya.cmds.formLayout( form, edit=True, attachForm=[(tabs, 'top', 0), (tabs, 'left', 0), (tabs, 'bottom', 0), (tabs, 'right', 0)] )
    
    #maya.cmds.columnLayout('')
    #maya.cmds.scrollLayout('Global' , width=500, height=300, horizontalScrollBarThickness=16, verticalScrollBarThickness=16)

    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.textFieldGrp( windowName + '_sidePrefix', label='Side Prefix:', text='L_', en=True )
    maya.cmds.textFieldGrp( windowName + '_jointType', label='joint type:', text='IK_', en=True )
    maya.cmds.textFieldGrp( windowName + '_limbTypeName', label='Limb Type Name:', text='leg_', en=True )
    maya.cmds.radioButtonGrp( windowName + '_jointAimAxis', label='Joint Aim Axis:', labelArray3=['X', 'Y', 'Z'], numberOfRadioButtons=3, en=True, sl=1 )
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldButtonGrp( windowName + '_joints', label='Get Joints:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_joints' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line2 )
    maya.cmds.textFieldButtonGrp( windowName + '_curve', label='Get SplineIK Curve:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_curve' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line3 )
    maya.cmds.textFieldButtonGrp( windowName + '_grp', label='Get Group:', text='char_GRP  DO_NOT_ALTER_GRP   curves_GRP', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_grp' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= '' )
    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.button(label='?', height = questionButtonHeight)
    maya.cmds.text( label= '   ' )
    maya.cmds.button(label='?', height = questionButtonHeight)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):
    sidePrefix = maya.cmds.textFieldGrp( windowName + '_sidePrefix', q=True, text=True )
    jointType = maya.cmds.textFieldGrp( windowName + '_jointType', q=True, text=True )
    limbTypeName = maya.cmds.textFieldGrp( windowName + '_limbTypeName', q=True, text=True )
    jaa = maya.cmds.radioButtonGrp( windowName + '_jointAimAxis', q=True, sl=True )
    jointAimAxis = whichAxis(jaa)[1]
    getCurve = maya.cmds.textFieldButtonGrp( windowName + '_curve', q=True, text=True )
    splineIkCurve = getCurve.split()[0]
    getJoints = maya.cmds.textFieldButtonGrp( windowName + '_joints', q=True, text=True )
    joints = getJoints.split()
    getGroup = maya.cmds.textFieldButtonGrp( windowName + '_grp', q=True, text=True )
    groupCurve = getGroup.split()

    sidePrefix = 'L_'
    jointType = 'IK_'
    limbTypeName = 'leg_'
    prefix = sidePrefix + jointType + limbTypeName


    jointAimAxis = 'X'

    howManyNodes = int(math.ceil(len(joints) / 3)) #This divided by three because of X,Y,Z

    setUpGrp(groupCurve)
    print ('joints[0:(len(joints)-1)] = ' + str(joints[0:(len(joints)-1)]))

    splineIKstretchjoints = setUpSplineIKstretch(joints[0:(len(joints)-1)],prefix,splineIkCurve,jointAimAxis)

line1 = '    SELECT ALL THE JOINTS THAT MAKE UP THE IK JOINT CHAIN, IN ORDER, FROM START TO END:-'
line2 = '    SELECT THE MAIN CTRL, THEN THE START CTRL, FINALLY THE END CTRL:-'
line3 = '    SELECT OR TYPE IN HIERARCHICAL ORDER THE GROUP THAT THE DIMENSION NODE IS TO BE GROUPED UNDER'
ver = ' : ver 01.001 : '
windowTitle = 'Set Up Spline IK Stretch' + ver
rebuildCurveWindowName = 'SetUpSplineIKstretch'
deleteWindow(rebuildCurveWindowName)
buildWindow(rebuildCurveWindowName,windowTitle,line1,line2,line3)

Python: Set Up IK Stretch
Submitted by admin on Wed, 10/22/2014 - 05:53
# USE : 
# REQUIRES:
#     1. getWStransform()
#    2. setWStransform()
#    3. setUpGrp()
#    4. whichAxis()
#    5. editTxtGrpButtonArray
#    6. deleteWindow()
# NOTES : 
#     1. SELECT ALL THE JOINTS THAT MAKE UP THE IK JOINT CHAIN, IN ORDER, FROM START TO END:-'
#     2. SELECT THE MAIN CTRL, THEN THE START CTRL, FINALLY THE END CTRL:-'
#     3. SELECT OR TYPE IN HIERARCHICAL ORDER THE GROUP THAT THE DIMENSION NODE IS TO BE GROUPED UNDER'

def setUpIKstretch2(prefix,jointAimAxis,limbTypeName,ikJointArray,howManyNodes,mainCTRL,startCTRL,endCTRL,ikHndle,dimGroup):
    #select second and last joint of Ik Chain, then the ctrl
    howManyJoints = len(ikJointArray)
    
    autoSwitchAttr = '.autoStretchIK'#must be boolean
    stretchIKAttr = '.stretchIK'
    stretchNormaliseNode = prefix + 'stretchNormalise_setRange'

    #DETERMINE WHETHER REMAP NODE IS INTERPRET CURVE IS LINEAR (1) OR SMOOTH (2)
    remapNodeInterp = 2
    stretchInfluence = 2

    IKNormaliseNode = prefix + 'normalize_multiplyDivide'
    IKMultiplierNode = prefix + 'multiplier_multiplyDivide'
    IKConditionNode = prefix + 'autoStretch_condition'
    IKScaleLimiterNode = prefix + 'limit_multiplyDivide'
    IKAutoStretchBlendNode = prefix + 'autoStretch_blend'
    IKStretchBlendNode = prefix + 'stretch_blend'
    IKStretchDampener = prefix + 'StretchDampener_condition'
    IKStretchRemapNode = prefix + 'stretchDampenRemap_remapValue'
    IKStretchBlendNode = prefix + 'stretchDampenBlend_blend'
    IKDampenValueNode = prefix + 'DampenValue_multiplyDivide'
    dampenAmount = 0.960

    startJoint = ikJointArray[0]
    print('setUpIKstretch :: startJoint = ' + str(startJoint))
    endJoint = ikJointArray[len(ikJointArray)-1]
    print('setUpIKstretch :: endJoint = ' + str(endJoint))

    distanceName = prefix + 'distanceDimension1'

    distanceNode = maya.cmds.distanceDimension( sp=(-2, 0, 0), ep=(2, 0, 0) )
    
    print('setUpIKstretch :: dimGroup = ' + str(dimGroup))
    maya.cmds.parent(distanceNode,dimGroup)
    distanceTrans = maya.cmds.listRelatives(distanceNode,p=True,f=True)
    distLocators = maya.cmds.listConnections(distanceNode,t='locator')
    print('setUpIKstretch :: distLocators = ' + str(distLocators))
    startLoc = maya.cmds.rename(distLocators[0],prefix + 'start_dim_LOC')
    endLoc = maya.cmds.rename(distLocators[1],prefix + 'end_dim_LOC')
    startLocPos = getWStransform(startJoint)
    setWStransform(startLoc,startLocPos)
    endLocPos = getWStransform(endJoint)
    setWStransform(endLoc,endLocPos)
    distanceName = maya.cmds.rename(distanceTrans[0],distanceName)
    print('setUpIKstretch :: distanceName = ' + str(distanceName))

    print('setUpIKstretch :: startLoc = ' + str(startLoc))
    print('setUpIKstretch :: startCTRL = ' + str(startCTRL))
    #startParent = None
    if(limbTypeName == 'arm_'):
        maya.cmds.parent(startLoc,startCTRL,a=True)
        maya.cmds.parent(endLoc,mainCTRL,a=True)
    else:
        endParent = maya.cmds.parentConstraint(endLoc,endCTRL,mo=True)
        maya.cmds.delete(endParent)
        print('setUpIKstretch :: endLoc = ' + str(endLoc))
        print('setUpIKstretch :: mainCTRL = ' + str(mainCTRL))
        maya.cmds.parent(endLoc,mainCTRL,a=True)
        #startParent = maya.cmds.parentConstraint(startLoc,startCTRL,mo=True)
        #maya.cmds.parentConstraint(startLoc,startCTRL,mo=True)
        maya.cmds.parent(startLoc,startCTRL,a=True)
    
    
    #START///////////////////////////////////CREATE CONDITION, NORMALISE MULTIPLYDIVIDE NODE AND 
    #START///////////////////////////////////CONNECT THE DISTANCE NODES DISTANCE ATTRIBUTE TO NORMALISE MULTIPLYDIVIDE NODES INPUT1X 
    #START///////////////////////////////////CONNECT THE NORMALISE MULTIPLYDIVIDE NODES OUPUTX TO 1st TERM OF CONDITION NODE
    
    #create set range node to normalise the stretch IK attribute*********************START**********create set range node to normalise the stretch IK attribute
    setRangeNode = maya.cmds.shadingNode('setRange',n=stretchNormaliseNode,au=True)
    connector = mainCTRL + stretchIKAttr
    socket = setRangeNode + '.valueX'
    maya.cmds.connectAttr(connector, socket, force=True)

    maya.cmds.setAttr(setRangeNode + '.oldMaxX', 10)
    maya.cmds.setAttr(setRangeNode + '.maxX', 1)
    #create set range node to normalise the stretch IK attribute*********************END**********create set range 
    
    #CREATE NORMALISE MULTIPLYDIVIDE NODE************************************************************START**********CREATE NORMALISE MULTIPLYDIVIDE NODE
    normaliseNode = maya.cmds.shadingNode('multiplyDivide',n=IKNormaliseNode + '1',au=True)
    connector = distanceName + '.distance'
    socket = normaliseNode + '.input1X'
    maya.cmds.connectAttr(connector, socket, force=True)

    #SET INPUT2X TO DISTANCE VALUE AND SET **************************************************************START**********SET INPUT2X TO DISTANCE VALUE AND SET 
    #MULTIPLYDIVIDE NODES OPERATION TO DIVIDE************************************************************START**********MULTIPLYDIVIDE NODES OPERATION TO DIVIDE
    socketAttribute = '.input2X'

    maya.cmds.setAttr(normaliseNode + '.operation', 2)
    distance = maya.cmds.getAttr(connector)
    print ('setUpIKstretch :: distance = ' + str(distance))

    maya.cmds.setAttr(normaliseNode + socketAttribute, distance) 
    #set Normalise nodes Z output to 1; ie 1 / 1 = 1. This will be connected to $stretch input 1R
    maya.cmds.setAttr(normaliseNode + '.input1Z', 1)
    maya.cmds.setAttr(normaliseNode + '.input2Z', 1)

    #SET INPUT2X TO DISTANCE VALUE AND SET **************************************************************END**********SET INPUT2X TO DISTANCE VALUE AND SET 
    #MULTIPLYDIVIDE NODES OPERATION TO DIVIDE************************************************************END**********MULTIPLYDIVIDE NODES OPERATION TO DIVIDE

    #CREATE NORMALISE MULTIPLYDIVIDE NODE************************************************************END**********CREATE NORMALISE MULTIPLYDIVIDE NODE

    stretchRemapNode = maya.cmds.shadingNode('remapValue',n=IKStretchRemapNode + '1',au=True) 
    socket =  stretchRemapNode + '.inputValue'
    connector =  normaliseNode + '.outputX'  

    maya.cmds.connectAttr(connector, socket, force=True)

    maya.cmds.setAttr(stretchRemapNode + '.value[0].value_Position',0.0)
    maya.cmds.setAttr(stretchRemapNode + '.value[0].value_FloatValue',0.0)
    maya.cmds.setAttr(stretchRemapNode + '.value[0].value_Interp',remapNodeInterp)

    maya.cmds.setAttr(stretchRemapNode + '.value[1].value_Position',1.0)
    maya.cmds.setAttr(stretchRemapNode + '.value[1].value_FloatValue',0.0)
    maya.cmds.setAttr(stretchRemapNode + '.value[1].value_Interp',remapNodeInterp)

    maya.cmds.setAttr(stretchRemapNode + '.value[2].value_FloatValue',1.0)
    maya.cmds.setAttr(stretchRemapNode + '.value[2].value_Position',0.5)
    maya.cmds.setAttr(stretchRemapNode + '.value[2].value_Interp',remapNodeInterp)

    maya.cmds.setAttr(stretchRemapNode + '.inputMin',0)
    maya.cmds.setAttr(stretchRemapNode + '.inputMax',2)

    StretchBlendNode = maya.cmds.shadingNode('blendColors',n=IKStretchBlendNode + '1',au=True) 

    socket =  StretchBlendNode + '.blender'
    connector =  stretchRemapNode + '.outValue'  

    maya.cmds.connectAttr(connector, socket, force=True)

    dampenValueNode = maya.cmds.shadingNode('multiplyDivide',n=IKDampenValueNode + '1',au=True) 
    
    maya.cmds.setAttr(dampenValueNode + '.input1X',dampenAmount)
    maya.cmds.setAttr(dampenValueNode + '.input1Y',1)
    socket = StretchBlendNode + '.color2R'
    connector = dampenValueNode + '.outputX'   

    maya.cmds.connectAttr(connector, socket, force=True)

    socket = StretchBlendNode + '.color1R'
    connector = dampenValueNode + '.outputY'   

    maya.cmds.connectAttr(connector, socket, force=True)

    stretchDampenerNode = maya.cmds.shadingNode('condition',n=IKStretchDampener + '1',au=True) 
    socket =  stretchDampenerNode + '.firstTerm'
    connector =  StretchBlendNode + '.outputR'  

    maya.cmds.connectAttr(connector, socket, force=True)

    maya.cmds.setAttr(stretchDampenerNode + '.operation',0)
    maya.cmds.setAttr(stretchDampenerNode + '.secondTerm',1)
    maya.cmds.setAttr(stretchDampenerNode + '.colorIfTrueR',1)
    
    socket =  stretchDampenerNode + '.colorIfFalseR'
    connector =  StretchBlendNode + '.outputR'  

    maya.cmds.connectAttr(connector, socket, force=True)

    #??????????????????????????THIS IS REDUNDANT??????????????????????????????
    #START/////////////////////////////////////////////////////////////CREATE LIMITER MULTIPLYDIVIDE NODE
    limiterNode = maya.cmds.shadingNode('multiplyDivide',n=IKScaleLimiterNode + '1',au=True) 
    
    IKScaleLimiterNode = limiterNode

    #CONNECT NORMALISE MULTIPLYDIVIDE NODES OUPUTX TO ".colorIfFalseR" OF CONDITION NODE
    socket = limiterNode + '.input2X'
    connector = stretchDampenerNode + '.outColorR'   

    maya.cmds.connectAttr(connector, socket, force=True)

    socket = limiterNode + '.input1X'
    connector = normaliseNode + '.outputX'   

    maya.cmds.connectAttr(connector, socket, force=True)

    #END//////////////////////////////////////////////////////////////CREATE LIMITER MULTIPLYDIVIDE NODE
    #??????????????????????????THIS IS REDUNDANT??????????????????????????????

    #CREATE CONDITION NODE AND CONNECT NORMALISE ********************************************START********CREATE CONDITION NODE AND CONNECT NORMALISE 
    #MULTIPLYDIVIDE NODES OUPUTX TO 1st TERM OF CONDITION NODE*******************************START********MULTIPLYDIVIDE NODES OUPUTX TO 1st TERM OF CONDITION NODE
    conditionNode = maya.cmds.shadingNode('condition',n=IKConditionNode + '1',au=True) 
    socket =  conditionNode + '.firstTerm'
    connector =  normaliseNode + '.outputX'  

    maya.cmds.connectAttr(connector, socket, force=True)

    maya.cmds.setAttr(conditionNode + '.operation',4)
    maya.cmds.setAttr(conditionNode + '.secondTerm',1)
    maya.cmds.setAttr(conditionNode + '.colorIfTrueR',1)

    #CONNECT NORMALISE MULTIPLYDIVIDE NODES OUPUTX TO ".colorIfFalseR" OF CONDITION NODE
    socket = conditionNode + '.colorIfFalseR'
    connector = IKScaleLimiterNode + '.outputX'   

    maya.cmds.connectAttr(connector, socket, force=True)

    #CREATE CONDITION NODE AND CONNECT NORMALISE ********************************************END********REATE CONDITION NODE AND CONNECT NORMALISE 
    #MULTIPLYDIVIDE NODES OUPUTX TO 1st TERM OF CONDITION NODE*******************************END********MULTIPLYDIVIDE NODES OUPUTX TO 1st TERM OF CONDITION NODE

    #CREATE AUTO STETCH ON AND OFF NODE********************************************START********CREATE AUTO STETCH ON AND OFF NODE
    #connect waist CTRL auto switch to the first term
    connector = mainCTRL + autoSwitchAttr
    socket = setRangeNode + '.valueY'
    maya.cmds.connectAttr(connector, socket, force=True)

    maya.cmds.setAttr(setRangeNode + '.oldMaxY', 10)
    maya.cmds.setAttr(setRangeNode + '.maxY', 1)

    autoStretch = maya.cmds.shadingNode('blendColors',n=IKAutoStretchBlendNode + '1',au=True) 
    socket = autoStretch + '.blender' #waist CTRL attribute auto stretch via set Range
    connector = setRangeNode + '.outValueY' 
    maya.cmds.connectAttr(connector, socket, force=True)

    #from auto stretch condition node;  $conditionNode 
    socket = autoStretch + '.color1R'
    connector = conditionNode + '.outColorR'
    maya.cmds.connectAttr(connector, socket, force=True)

    #from stretch  node;  $stretch 
    socket = autoStretch + '.color2R'
    connector = IKScaleLimiterNode + '.outputX'
    maya.cmds.connectAttr(connector, socket, force=True)
    #CREATE AUTO STETCH ON AND OFF NODE********************************************END********CREATE AUTO STETCH ON AND OFF NODE

    #CREATE STRETCH ON AND OFF NODE**************************************************************START*******************CREATE STRETCH ON AND OFF NODE
    stretch =  maya.cmds.shadingNode('blendColors',n=IKStretchBlendNode + '1',au=True) 
    socket = stretch + '.color2R'
    connector = normaliseNode + '.outputZ'
    maya.cmds.connectAttr(connector, socket, force=True)
    
    socket = stretch + '.color1R'
    connector =  autoStretch + '.outputR'
    maya.cmds.connectAttr(connector, socket, force=True)

    #connect $setRangeNode .outpUtX to $stretch blend input
    socket =  stretch + '.blender'
    connector =  setRangeNode + '.outValueX'
    maya.cmds.connectAttr(connector, socket, force=True)

    #CONNECT ATTRIBUTE 'stretchInfluence' to stretchRemapNode
    checkAttrExist(mainCTRL ,'stretchDampen','double',0,10,dampenAmount,False,True)
    source = mainCTRL + '.stretchDampen'
    destination = dampenValueNode + '.input1X' ##stretchRemapNode + '.inputMax'
    maya.cmds.connectAttr(source, destination, force=True)

    #CONNECT ATTRIBUTE 'stretchInfluence' to stretchRemapNode
    checkAttrExist(mainCTRL ,'stretchInfluence','double',0,10,stretchInfluence,False,True)
    source = mainCTRL + '.stretchInfluence'
    destination = stretchRemapNode + '.inputMax'
    maya.cmds.connectAttr(source, destination, force=True)

    #CREATE STRETCH ON AND OFF NODE**************************************************************END*******************CREATE STRETCH ON AND OFF NODE

    IKConditionNode = conditionNode
    IKNormaliseNode = normaliseNode
    IKAutoStretchBlendNode = autoStretch
    IKStretchBlendNode = stretch
    stretchNormaliseNode = setRangeNode

    #END///////////////////////////////////CREATE CONDITION, NORMALISE MULTIPLYDIVIDE NODE AND 
    #END///////////////////////////////////CONNECT THE DISTANCE NODES DISTANCE ATTRIBUTE TO NORMALISE MULTIPLYDIVIDE NODES INPUT1X 
    #END///////////////////////////////////CONNECT THE NORMALISE MULTIPLYDIVIDE NODES OUPUTX TO 1st TERM OF CONDITION NODE

    #START/////////////////////////////////////////////////////////////MULTIPLIER NODES READY TO BE CONNECT RO IK JOINT TRANSLATEX
    multiplierNodes = []
    for i in range(0,howManyNodes,1):
        multiplierNode = maya.cmds.shadingNode('multiplyDivide',n=IKMultiplierNode + '1',au=True)
        #multiplierNodes[i] = multiplierNode
        multiplierNodes.append(multiplierNode)

    #END///////////////////////////////////////////////////////////////MULTIPLIER NODES READY TO BE CONNECT RO IK JOINT TRANSLATEX

    #START/////////////////////////////////////////////////////////////CONNECT THE CONDITION NODE TO MULTIPLIER NODES READY TO BE CONNECT TO IK JOINT TRANSLATEX
    connectorAttribute1 = '.outputR'
    socketAttribute1 = '.input' 
    connector1 = IKStretchBlendNode + connectorAttribute1

    connectorAttribute2 = '.output'

    whichJoint = 1
    brake = 0

    #CONNECT CONDITION NODE TO MULYIPLIER NODES
    for i in range(0,howManyNodes,1):
        multiply = i + 1 #use to select the right joint in $sel[] and "spine_multiplier_multiplyDivide" node
    
        whichAxis = [' ', 'X', 'Y', 'Z']
        for j in range(1,4,1):
            if(brake == 0):
                socket1 = multiplierNodes[i] + (socketAttribute1 + '2' + whichAxis[j])
                maya.cmds.connectAttr(connector1, socket1, force=True)
        
                getAttr = maya.cmds.getAttr(ikJointArray[whichJoint] + '.t' + jointAimAxis.lower())
                setAttr = maya.cmds.setAttr(multiplierNodes[i] + (socketAttribute1 + '1' + whichAxis[j]), getAttr)
        
                connector2 = IKMultiplierNode + str(multiply) + (connectorAttribute2 + whichAxis[j])
                socket2 = (ikJointArray[whichJoint] + '.t' + jointAimAxis.lower())
                maya.cmds.connectAttr(connector2, socket2, force=True)

                whichJoint = whichJoint + 1
    
                print ('setUpIKstretch :: whichJoint = ' + str(whichJoint))
                print ('setUpIKstretch :: howManyJoints = ' + str(howManyJoints))

                #LOOP BREAK TO CATER FOR ODD NUMBER OF JOINTS
                if(whichJoint == howManyJoints):
                    brake = 1
    
        print ('setUpIKstretch :: i = ' + str(i) )

    #END//////////////////////////////////////////////////////////////CONNECT THE CONDITION NODE TO MULTIPLIER NODES READY TO BE CONNECT TO IK JOINT TRANSLATEX
    #================================================================================================================================
    #END++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    #^^^^^^^^^^^^^^^-----TESTED AND WORKS-----^^^^^^^^^^^^^^^!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
###############################################################################################
#     GUI:    
###############################################################################################

def buildWindow(windowName,windowTitle, line1,line2,line3):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 300))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')

    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.textFieldGrp( windowName + '_sidePrefix', label='Side Prefix:', text='L', en=True )
    maya.cmds.textFieldGrp( windowName + '_jointType', label='joint type:', text='IK', en=True )
    maya.cmds.textFieldGrp( windowName + '_limbTypeName', label='Limb Type Name:', text='leg', en=True )
    maya.cmds.radioButtonGrp( windowName + '_jointAimAxis', label='Joint Aim Axis:', labelArray3=['X', 'Y', 'Z'], numberOfRadioButtons=3, en=True, sl=1 )
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldButtonGrp( windowName + '_joints', label='Get Joints:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_joints' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line2 )
    maya.cmds.textFieldButtonGrp( windowName + '_mainCtrl', label='Get Main Control:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_mainCtrl' + '","textFieldButtonGrp")' )
    maya.cmds.textFieldButtonGrp( windowName + '_startCtrl', label='Get Start Control:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_startCtrl' + '","textFieldButtonGrp")' )
    maya.cmds.textFieldButtonGrp( windowName + '_endCtrl', label='Get End Control:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_endCtrl' + '","textFieldButtonGrp")' )
    maya.cmds.textFieldButtonGrp( windowName + '_ikHandle', label='Get IK Handle:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ikHandle' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line3 )
    maya.cmds.textFieldButtonGrp( windowName + '_grp', label='Get Group:', text='char_GRP  DO_NOT_ALTER_GRP   dimension_GRP', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_grp' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= '' )
    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.button(label='?', height = questionButtonHeight)
    maya.cmds.text( label= '   ' )
    maya.cmds.button(label='?', height = questionButtonHeight)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):
    sp = maya.cmds.textFieldGrp( windowName + '_sidePrefix', q=True, text=True )
    sps = sp.split()
    jt = maya.cmds.textFieldGrp( windowName + '_jointType', q=True, text=True )
    jts = jt.split()
    lt = maya.cmds.textFieldGrp( windowName + '_limbTypeName', q=True, text=True )
    lts = lt.split()
    jaa = maya.cmds.radioButtonGrp( windowName + '_jointAimAxis', q=True, sl=True )
    jointAimAxis = whichAxis(jaa)[1]
    getMainCtrl = maya.cmds.textFieldButtonGrp( windowName + '_mainCtrl', q=True, text=True )
    mainCtrl = getMainCtrl.split()[0]
    getStartCtrl = maya.cmds.textFieldButtonGrp( windowName + '_startCtrl', q=True, text=True )
    startCtrl = getStartCtrl.split()[0]
    getEndCtrl = maya.cmds.textFieldButtonGrp( windowName + '_endCtrl', q=True, text=True )
    endCtrl = getEndCtrl.split()[0]
    getJoints = maya.cmds.textFieldButtonGrp( windowName + '_joints', q=True, text=True )
    joints = getJoints.split()
    getIkHandle = maya.cmds.textFieldButtonGrp( windowName + '_ikHandle', q=True, text=True )
    mainIkhandle = getIkHandle.split()
    getGroup = maya.cmds.textFieldButtonGrp( windowName + '_grp', q=True, text=True )
    groupDim = getGroup.split()

    sidePrefix = sps[0] + '_'
    jointType = jts[0] + '_'
    limbTypeName = lts[0] + '_'
    prefix = sidePrefix + jointType + limbTypeName


    howManyNodes = int(math.ceil(len(joints) / 3)) #This divided by three because of X,Y,Z

    setUpGrp(groupDim)

    setUpIKstretch2(prefix,jointAimAxis,limbTypeName,joints,howManyNodes,mainCtrl,startCtrl,endCtrl,mainIkhandle,groupDim[len(groupDim)-1])


Python: Maya: Set Up IK Spline IK Stretch

# USE : sets up spline IK to be able to stretch
# REQUIRES:
#    1. whichAxis(value)
#    2. editTxtGrpButtonArray
#    3. deleteWindow()
# NOTES : 
# 1. SELECT ALL THE JOINTS THAT MAKE UP THE IK JOINT CHAIN, IN ORDER, FROM START TO END
# 2. SELECT THE MAIN CTRL, THEN THE START CTRL, FINALLY THE END CTRL
# 3. SELECT OR TYPE IN HIERARCHICAL ORDER THE GROUP THAT THE DIMENSION NODE IS TO BE GROUPED UNDER

def setUpSplineIKstretch(jointArray,prefix,crve,aimAxis):
    splineNormaliseNode = prefix + 'spline_normalize_multiplyDivide'
    splineMultiplyNode = prefix + 'spline_multiplier_multiplyDivide'
    curveInfo = prefix + 'spline_curveInfo1'

    howManyJoints = len(jointArray)
    print ('howManyJoints = ' + str(howManyJoints))
    print ('howManyJoints / 3 = ' + str(float(howManyJoints) / float(3)))
    howManyNodes = int(math.ceil(float(howManyJoints) / float(3)))
    print ('howManyNodes = ' + str(howManyNodes))
    #START////////////////////////////////////////////////////////////////////////////////////CREATE CURVE INFO NODE FOR CHAR SPINE 
    #CREATE CURVE INFO AND MULTIPLYDIVIDE NODES
    curveInfoNode = maya.cmds.arclen(crve, ch=True)
    multiplierNode = maya.cmds.shadingNode('multiplyDivide',n=splineNormaliseNode + '1',au=True)

    splineNormalise = multiplierNode #ENSURE THAT THERE CONTINUITY THROUGH OUT THE SCRIPT

    #CONNECT ARCLENGTH TO INPUT1X 
    socket = multiplierNode + '.input1X'
    connector = curveInfoNode + '.arcLength'
    maya.cmds.connectAttr(connector, socket, force=True)

    #SET INPUT2X TO ARCLENGTH VALUE AND SET MULTIPLEDIVED NODES OPERATION TO DIVIDE
    socketAttribute = '.input2X'

    maya.cmds.setAttr(multiplierNode + '.operation',2)
    arcLength = maya.cmds.getAttr(connector)

    maya.cmds.setAttr(multiplierNode + '.input2X', arcLength)

    maya.cmds.rename(curveInfoNode, curveInfo)
    #print('splineMultiplyNode = ' + str(splineMultiplyNode))
    #END/////////////////////////////////////////////////////////////////////////////////////CREATE CURVE INFO NODE FOR CHAR SPINE 

    #START///////////////////////////////////////////////////////////////////////////////////CREATE MULTIPLYDIVIDE NODES TO BE CONNECTED TO THE INDIVIDUAL JOINTS TRANSLATEX 
        splineMultiply = []
        #CREATE MULTIPLYDIVIDE NODES 
        for i in range(0,howManyNodes,1):
        temp = maya.cmds.shadingNode('multiplyDivide', n=splineMultiplyNode + str(1), au=True)
        splineMultiply.append(temp)
        
    print ('splineMultiply = ' + str(splineMultiply))

    connectorAttribute1 = '.outputX' #change this variable
    socketAttribute1 = '.input' #change this variable
    connector1 = splineNormalise + connectorAttribute1
    connectorAttribute2 = '.output'
    
    whichJoint = 1

    whichAxis = [' ', 'X', 'Y', 'Z']
    brake = 0

    print ('jointArray 1 = ' + str(jointArray))

    #CONNECT THE NORMALISE NODE TO THE MULTIPLYDIVIDE NODES, COPY SPINE JOINT TRANSLATE-X TO MULTIPLYDIVIDE NODES INPUT 1XYZ ATTRIBUTES AND 
    #CONNECT MULTIPLYDIVIDE NODES OUTPUT XYZ TO SPINE JOINT TRANSLATEX
    for i in range(0, howManyNodes, 1):
        
        #multiply = i + 1
    
        for j in range(1, 4, 1):
            if(brake == 0):
                
                #socket1 = splineMultiply + str(multiply) + (socketAttribute1 + '2' + whichAxis[j])
                socket1 = splineMultiply[i] + (socketAttribute1 + '2' + whichAxis[j])
                maya.cmds.connectAttr(connector1, socket1, force=True)
        
                getAttribute = maya.cmds.getAttr(jointArray[whichJoint] + '.t' + aimAxis.lower())
                #setAttr = maya.cmds.setAttr(splineMultiplyNode + str(multiply) + (socketAttribute1 + '1' + whichAxis[j]), getAttr)
                setAttr = maya.cmds.setAttr( splineMultiply[i] + (socketAttribute1 + '1' + whichAxis[j]), getAttribute)
        
                connector2 = splineMultiply[i] + (connectorAttribute2 + whichAxis[j])
                print ('connector2 = ' + str(connector2))
                socket2 = (jointArray[whichJoint] + '.t' + aimAxis.lower())
                print ('socket2 = ' + str(socket2))
                maya.cmds.connectAttr(connector2, socket2, force=True)

                whichJoint = whichJoint + 1
    
                print ('whichJoint = ' + str(whichJoint))
                print ('howManyJoints = ' + str(howManyJoints))

                #LOOP BREAK TO CATER FOR ODD NUMBER OF JOINTS
                if(whichJoint == howManyJoints):
                    brake = 1
                    print ('brake = ' + str(brake))

    #END/////////////////////////////////////////////////////////////////////////////////////CREATE MULTIPLYDIVIDE NODES TO BE CONNECTED TO THE INDIVIDUAL JOINTS TRANSLATEX 
    
###############################################################################################
#     GUI:    
###############################################################################################

def buildWindow(windowName,windowTitle, line1,line2,line3):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 300))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')
    #form = maya.cmds.formLayout(windowName + '_form1')
    #tabs = maya.cmds.tabLayout(windowName + '_tabs1', innerMarginWidth=5, innerMarginHeight=5)
    #maya.cmds.formLayout( form, edit=True, attachForm=[(tabs, 'top', 0), (tabs, 'left', 0), (tabs, 'bottom', 0), (tabs, 'right', 0)] )
    
    #maya.cmds.columnLayout('')
    #maya.cmds.scrollLayout('Global' , width=500, height=300, horizontalScrollBarThickness=16, verticalScrollBarThickness=16)

    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.textFieldGrp( windowName + '_sidePrefix', label='Side Prefix:', text='L_', en=True )
    maya.cmds.textFieldGrp( windowName + '_jointType', label='joint type:', text='IK_', en=True )
    maya.cmds.textFieldGrp( windowName + '_limbTypeName', label='Limb Type Name:', text='leg_', en=True )
    maya.cmds.radioButtonGrp( windowName + '_jointAimAxis', label='Joint Aim Axis:', labelArray3=['X', 'Y', 'Z'], numberOfRadioButtons=3, en=True, sl=1 )
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldButtonGrp( windowName + '_joints', label='Get Joints:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_joints' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line2 )
    maya.cmds.textFieldButtonGrp( windowName + '_curve', label='Get SplineIK Curve:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_curve' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line3 )
    maya.cmds.textFieldButtonGrp( windowName + '_grp', label='Get Group:', text='char_GRP  DO_NOT_ALTER_GRP   curves_GRP', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_grp' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= '' )
    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.button(label='?', height = questionButtonHeight)
    maya.cmds.text( label= '   ' )
    maya.cmds.button(label='?', height = questionButtonHeight)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):
    sidePrefix = maya.cmds.textFieldGrp( windowName + '_sidePrefix', q=True, text=True )
    jointType = maya.cmds.textFieldGrp( windowName + '_jointType', q=True, text=True )
    limbTypeName = maya.cmds.textFieldGrp( windowName + '_limbTypeName', q=True, text=True )
    jaa = maya.cmds.radioButtonGrp( windowName + '_jointAimAxis', q=True, sl=True )
    jointAimAxis = whichAxis(jaa)[1]
    getCurve = maya.cmds.textFieldButtonGrp( windowName + '_curve', q=True, text=True )
    splineIkCurve = getCurve.split()[0]
    getJoints = maya.cmds.textFieldButtonGrp( windowName + '_joints', q=True, text=True )
    joints = getJoints.split()
    getGroup = maya.cmds.textFieldButtonGrp( windowName + '_grp', q=True, text=True )
    groupCurve = getGroup.split()

    sidePrefix = 'L_'
    jointType = 'IK_'
    limbTypeName = 'leg_'
    prefix = sidePrefix + jointType + limbTypeName


    jointAimAxis = 'X'

    howManyNodes = int(math.ceil(len(joints) / 3)) #This divided by three because of X,Y,Z

    setUpGrp(groupCurve)
    print ('joints[0:(len(joints)-1)] = ' + str(joints[0:(len(joints)-1)]))

    splineIKstretchjoints = setUpSplineIKstretch(joints[0:(len(joints)-1)],prefix,splineIkCurve,jointAimAxis)

line1 = '    SELECT ALL THE JOINTS THAT MAKE UP THE IK JOINT CHAIN, IN ORDER, FROM START TO END:-'
line2 = '    SELECT THE MAIN CTRL, THEN THE START CTRL, FINALLY THE END CTRL:-'
line3 = '    SELECT OR TYPE IN HIERARCHICAL ORDER THE GROUP THAT THE DIMENSION NODE IS TO BE GROUPED UNDER'
ver = ' : ver 01.001 : '
windowTitle = 'Set Up Spline IK Stretch' + ver
rebuildCurveWindowName = 'SetUpSplineIKstretch'
deleteWindow(rebuildCurveWindowName)
buildWindow(rebuildCurveWindowName,windowTitle,line1,line2,line3)

Python: Maya: Set Up IK FK Visibility Switch

import maya.cmds
import random
import math
# USE : 
# REQUIRES:
#    1. getShapeNodes()
# NOTES : 
#     1. SELECT IK CONTROL OBJECTS
#    2. SELECT FK CONTROL OBJECTS
#    3. TYPE THE NAME OF THE IKFK SWITCH ATTRIBUTE
#    4. SELECT IKFK SWITCH CONTROL
#    5. SELECT OR TYPE EXISTING IKFK SETRANGE NODE (optional)

def setUpIkFfVisibilitySwitch2(prefix,ikArray,fkArray,ctrl,attribute):
    checkAttrExist(ctrl,attribute,'double',0,10,0,True,False)
    newSetRangeName = prefix + 'IKFK_switch_setRange'#'IKFK_vis_switch_setRange'
    setRangeNode = ''
    setRangeName = prefix + 'IKFK_setRange'# e.g. L_arm_IKFK_setRange

    source = ctrl + '.' + attribute

    if maya.cmds.objExists(setRangeName):
        setRangeNode = setRangeName
    else:
        setRangeNode = maya.cmds.shadingNode('setRange',n=setRangeName,au=True)
        maya.cmds.setAttr(setRangeNode + '.oldMinX',0)
        maya.cmds.setAttr(setRangeNode + '.oldMinY',0)
        maya.cmds.setAttr(setRangeNode + '.oldMaxX',10)
        maya.cmds.setAttr(setRangeNode + '.oldMaxY',10)
        maya.cmds.setAttr(setRangeNode + '.minX',1)
        maya.cmds.setAttr(setRangeNode + '.minY',0)
        maya.cmds.setAttr(setRangeNode + '.maxX',0)
        maya.cmds.setAttr(setRangeNode + '.maxY',1)
            
        destination = setRangeNode + '.valueX'
        maya.cmds.connectAttr(source, destination, force=True)

        destination = setRangeNode + '.valueY'
        maya.cmds.connectAttr(source, destination, force=True)

    source = setRangeNode + '.outValueX'
    print('setUpIkFfVisibilitySwitch :: ikArray = ' + str(ikArray))

    print('setUpIkFfVisibilitySwitch :: ik ')
    for c in ikArray:
        if maya.cmds.objExists(c):
            print('setUpIkFfVisibilitySwitch :: ik : c = ' + str(c))
            destination = c + '.visibility'
            maya.cmds.connectAttr(source, destination, force=True)

    source = setRangeNode + '.outValueY'

    for c in fkArray:
        if maya.cmds.objExists(c):
            print('setUpIkFfVisibilitySwitch :: fk : c = ' + str(c))
            destination = c + '.visibility'
            maya.cmds.connectAttr(source, destination, force=True)

    print('setUpIkFfVisibilitySwitch :: setRangeNode = ' + str(setRangeNode))
    return setRangeNode
    
###############################################################################################
#    NO GUI:    
###############################################################################################

#0=Right, 1=Left, 2=Centre, 3=Misc
IKcolour = [14,13,17]
FKColour = [23,31,25]
splineIKColour = [6,15,29]#[17,21,23]
clothColour = [9,30,21]
faceColour = [22,10,26]
misc = [4,7,11]

SplnCtrlColour = splineIKColour[0]
ikctrlColour = IKcolour[0]
fkctrlColour = FKColour[0]

sel = maya.cmds.ls(selection=True)
sidePrefix = 'L_'
jointType = 'IK_'
vis = False


if(sidePrefix == 'L_'):
    SplnCtrlColour = splineIKColour[0]
    ikctrlColour = IKcolour[0]
    fkctrlColour = FKColour[0]
elif(sidePrefix == 'R_'):
    SplnCtrlColour = splineIKColour[1]
    ikctrlColour = IKcolour[1]
    fkctrlColour = FKColour[1]
else:
    SplnCtrlColour = splineIKColour[2]
    ikctrlColour = IKcolour[2]
    fkctrlColour = FKColour[2]


for i in sel:
    shape = getShapeNodes(i)[0][0]
    maya.cmds.setAttr(shape + '.visibility', False)

Python: Maya: Set Up Control Isolation

# USE : 
# REQUIRES:
#    1. checkAttrExist
#    2. editTxtGrpButtonArray
#    3. deleteWindow()

# NOTES : 
#    1. SELECT CONTROL OBJECTS
#    2. SELECT PARENT OBJECTS

def setUpControlIsolation(cntrl,parentObj,cntrlGrpName):
    grp = ''
    attrName = 'isolate'
    getParent = maya.cmds.listRelatives(cntrl,p=True,typ='transform')
    if(getParent != None):
        if(len(getParent) == 1):
            if(getParent[0] == cntrlGrpName):
                grp = cntrlGrpName
            else:
                grp = maya.cmds.group(em=True,n=cntrlGrpName)
                maya.cmds.parent(grp,getParent[0],r=True)
                maya.cmds.parent(cntrl,grp,r=True)
                print grp

    else:
        grp = maya.cmds.group(em=True,n=cntrlGrpName)
        maya.cmds.parent(cntrl,grp,r=True)
        print grp

    setRangeNode = cntrl + 'isolate_setRange'
    if(maya.cmds.objExists(setRangeNode) == False):
        setRangeNode = maya.cmds.shadingNode('setRange',n=cntrl + 'isolate_setRange',au=True)
    
###############################################################################################
#     GUI:    
###############################################################################################

def buildWindow(windowName, windowTitle, line1, line2):
    questionButtonHeight=23
    maya.cmds.window( windowName, title= windowTitle, s=True, iconName='Short Name', widthHeight=(500, 300))
    maya.cmds.frameLayout(  windowName + '_frameLayout1', label=' ', borderStyle="in", lv=False, bv=False, mw=10, mh=10)
    maya.cmds.columnLayout(windowName + '_column1', adjustableColumn=True)

    maya.cmds.text( label= '   ' )

    maya.cmds.rowLayout(windowName + '_row1',numberOfColumns=3, columnWidth3=(80, 80, 80), adjustableColumn3=3, columnAlign3=('left','left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0)])
    
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')

    maya.cmds.text( label= '   ' )

    maya.cmds.frameLayout(windowName + '_formBase', label='Tabs', lv=False, labelAlign='top', borderStyle='in')

    maya.cmds.rowLayout(windowName + '_row2',numberOfColumns=2, columnWidth2=(450, 20), adjustableColumn2=2, columnAlign2=('left','left'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
    
    maya.cmds.columnLayout(windowName + '_global1a', rs=3)
    maya.cmds.text( label= line1 )
    maya.cmds.textFieldButtonGrp( windowName + '_ctrl', label='Get Objects:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_ctrl' + '","textFieldButtonGrp")' )
    maya.cmds.text( label= line3 )
    maya.cmds.textFieldButtonGrp( windowName + '_parent', label='Type Attribute:', text='', buttonLabel='Select', en=True, bc='editTxtGrpButtonArray("' + windowName + '_parent' + '","textFieldButtonGrp")' )
    maya.cmds.setParent('..')

    maya.cmds.columnLayout(windowName + '_global1b', rs=3)
    maya.cmds.text( label= '   ' )
    maya.cmds.setParent('..')
    
    maya.cmds.setParent('..')
    #maya.cmds.setParent('..')
    #maya.cmds.setParent('..')

    maya.cmds.text( windowName + '_space1', label='' )
    maya.cmds.text( windowName + '_space2', label='' )
    maya.cmds.button(windowName + '_CreateSystem', label='Run Script', c='runWindow("' + windowName + '")' )

    maya.cmds.showWindow( windowName )


def runWindow(windowName):

    getCtrl = maya.cmds.textFieldButtonGrp( windowName + '_ctrl', q=True, text=True )
    ctrlArray = getCtrl.split()
    control = ctrlArray[0]

    getParent = maya.cmds.textFieldGrp( windowName + '_parent', q=True, text=True )
    p = getParent.split()
    parent = p[0]

    setUpControlIsolation(control,parent,control + '_GRP')

line1 = '    SELECT CONTROL OBJECTS :-'
line2 = '    SELECT PARENT OBJECTS :-'
windowTitle = 'Set Up Isolate Control'
rebuildCurveWindowName = 'setUpIsolateControl'
deleteWindow(rebuildCurveWindowName)
buildWindow(rebuildCurveWindowName, windowTitle, line1, line2)

Python: Maya: Lock and Hide Attributes Variable

This function ….

import maya.cmds
import random
import math
# USE : returns a limited list of nodes based on a breakerObj. Use it return only the joints of a leg rig prior to the foot joints for instance
# REQUIRES:
#    1. 
# NOTES : 
#     1. 

import maya.cmds
import random
import math

def lockHideAttr(obj,attrArray,lock,hide):
    for a in attrArray:
        maya.cmds.setAttr(obj + '.' + a, k=hide,l=lock)

Python: Maya: Lock and Hide Attributes

Python: Maya: Lock and Hide Attributes

This function hides and locks the attributes of a selected node

import maya.cmds
import random
import math
# USE : returns a limited list of nodes based on a breakerObj. Use it return only the joints of a leg rig prior to the foot joints for instance
# REQUIRES:
#    1. 
# NOTES : 
#     1. 

import maya.cmds
import random
import math

#SHOW AND UNLOCK ATTRIBUTES
lockHideAttr(ikfkSwitchCTRL,['tx','ty','tz','rx','ry','rz','sx','sy','sz'],False,True)