May 2016
1 / 4
May 2016
May 2016

I am almost done creating a rigged character. All of the joints are in place, the Joint Orient axes are aimed in the right directions, and all of the skinning is completed. All I have to do is apply controllers to the joints. Naturally, when I orient a controller to a joint, its rotational axes are no longer 0,0,0. I can freeze transformations, but when I do that, the rotational axes of the controller become oriented to the World instead of the joint.

Getting the rotational axes of the joints is easy because all you have to do is change the Joint Orient values. Is there are similar tool for woking with NURBS so that the rotational axes are not aligned with the World but still read as 0,0,0?

  • created

    May '16
  • last reply

    May '16
  • 3

    replies

  • 3.7k

    views

  • 1

    user

  • 1

    link

You have to group the controls, put the control values in the parent group and reset the control. This script does this automatically.

Script to orient controls in Maya92

"""
This script creates spaces for all selected objects.
If those are orientated controls, then script will
zero them out and transfer their rotations, translations
scales to their parent group
"""

import maya.cmds as cmds

def match_second_to_first(first, sec):
    """
    matches second position and rotation to the
    first position and rotation
    """
    cns = cmds.parentConstraint(first, sec)
    cmds.delete(cns)

def scale_sec_like_first(first, sec):
    """
    matches second scaling to first scaling
    """
    cns = cmds.scaleConstraint(first, sec)
    cmds.delete(cns)

def make_space_for(the_object, suffix):
    """
    this function makes space for selected control
    object based on the provided suffix
    """

    # this is to make sure that space name doesnt already exist:
    GRP = ""
    if cmds.objExists(the_object+"_"+suffix):
        i = 0

        # we are looping "i" until we find name that is not used
        while cmds.objExists(the_object+"_"+suffix+str(i)):
            i += 1

        cmds.warning("default space name is taken, "
                     "the object might already have "
                     "a space, adding number suffix")

        GRP = cmds.group(empty=True,
                         name=the_object+"_"+suffix+str(i))
    else:
        GRP = cmds.group(empty=True,
                         name=the_object+"_"+suffix)

    the_parent = cmds.listRelatives(the_object, parent=True)

    if the_parent is not None:
        cmds.parent(GRP, the_parent[0])
        cmds.parent(the_object, world=True)

    match_second_to_first(the_object, GRP)
    scale_sec_like_first(the_object, GRP)

    cmds.parent(the_object, GRP)

    match_second_to_first(GRP, the_object)
    scale_sec_like_first(GRP, the_object)

    try:
        cmds.makeIdentity(the_object, apply=True,
                          t=1, r=1, s=1, n=0)
    except:
        cmds.warning("Cannot freeze transformations for: "+
                     + the_object + ", is it skinned or connected?")

    return(GRP)

# this loop below loops through selection and
# creates spaces for each selected object/control
for obj in cmds.ls(selection=True):
    make_space_for(obj, "grp")

I had come to realize that it required creating a group for each controller, but I never knew that there was a script to do the job for me. Thank you for the reply. I tried out the script and it made things ten times easier.

"but I never knew that there was a script to do the job for me"

It's pretty easy to script these types of things after studying MELscript and Python/PyMel for a little while. I suggest you invest a little time into learning a bit. It'll totally make your life easier Nathan! :smiley:  You can automate most tasks in Maya with a few button clicks, after you've learned how to script the commands.