Friday, January 30, 2015

circle control script

Circle control script

This script creates a series of circle controls and circle control groups for every joint selected.

Notes:
  1. All joints MUST be named with a "JT_" prefix, as we have been doing in class.
  2. Joints must be selected starting in a parent-child descending order; in other words, select the top-most parent joint first, then the next child joint, then the next child joint, etc
  3. The selection set for the spinal column would in the following order:
    1. JT_spine_lumbar
    2. JT_spine_thoracic
    3. JT_neck
    4. JT_head
  4. The script will create a control for each joint, and connect the rotation channels of the joint to the control. The control is then grouped by itself. If it is controlling a joint that is the child of another joint in the current selection, it will parent the control's group to the controller of the parent. 
How to use:

Copy the script below the dashed line into the Python tab of your script editor. Select the joints you want to add controls to, making sure to select the joints in a parent-child descending order. In the script editor, choose command > execute.


-------------------------------------------------------------------------------------------------------------------

import maya.cmds as cmds

sl = cmds.ls(sl=1)
count = 0
lastS = None

for s in sl:
    ctrlName = s.replace("JT_", "CTL_")
    ctrl = cmds.circle( nr=(1, 0, 0), r=1, n=ctrlName)[0]
    offset = cmds.group(ctrl, n="GRP_" + ctrl )
    cmds.parentConstraint(s, offset, mo=0)
    cmds.delete(cmds.parentConstraint(s, offset))
    cmds.parentConstraint(ctrl, s, mo=0)
    if count > 0 :
        cmds.parent( offset, lastS )
    count = count + 1
    global lastS
    lastS = ctrl

No comments:

Post a Comment