Developer guide For riggers

Mutant Tools for Python developers

Mutant Tools is a block-based modular rigging system for Maya. Everything the UI does, it does by calling Python you can call yourself. This page teaches the whole surface: the mt API, how a block is defined and built, and how to ship your own blocks into the system.

  • 117mt methods
  • 133shipped blocks
  • 44control shapes
  • Maya 2022+Python 2 & 3

60-second quickstart#

Install by dragging easy_install.py into a Maya viewport. That copies the package into your maya/<version>/scripts folder, installs the shelf and registers the Mutant-Tools menu so it loads on every startup.

Then, in the Script Editor's Python tab:

maya script editor
from maya import cmds

import Mutant_Tools
from Mutant_Tools.Utils.Rigging import main_mutant

mt = main_mutant.Mutant()
nc, curve_data, setup = mt.import_configs()

# a control, coloured, with an offset group above it
ctrl = mt.controller(name='Hand', shape='hand', size=4, color='blue')
print(ctrl)
NoteConstructing Mutant() has a side effect: if the scene has no Mutant_Tools node it creates one, stamped with the build date and version as locked string attributes. That node is how a scene remembers which version of the tools built it.

Every block script starts the same way#

This header is the contract. The try/except around the import exists so a block can be run both as a loose script sitting in its own folder and as part of the installed package.

exec_my_thing_v001.py
from __future__ import absolute_import
from maya import cmds
import json
import os
from pathlib import Path

try:
    import importlib; from importlib import reload
except ImportError:
    import imp; from imp import reload

import Mutant_Tools
import Mutant_Tools.Utils.Rigging
from Mutant_Tools.Utils.Rigging import main_mutant
reload(Mutant_Tools.Utils.Rigging.main_mutant)

mt = main_mutant.Mutant()

TAB_FOLDER = '008_Props'        # which Blocks/ category this lives in
PYBLOCK_NAME = 'exec_my_thing'  # module name without the _vNNN suffix

The mental model#

Three ideas carry the whole system. Get these and the rest is API surface.

1. A block is a container

A Maya dagContainer named <Name>_Block, living under a Mutant_Build group. It holds the guides you place by hand. It is the thing an artist drags around.

2. A config is a network node

A sibling network node named <Name>_Config. Every option an artist can set is an attribute on it, plus the strings that say how to rebuild the block.

3. Build is re-runnable

Blocks and guides are the source. The rig is the output. Deleting the rig and rebuilding from the same blocks must give the same result - that is the whole point of the system.

So a scene mid-rig looks like this:

outliner
Mutant_Build                     <- group, holds every block
|-- L_Arm_Block                  <- dagContainer (the block)
|   `-- L_Shoulder_Guide ...     <- guides you place
|-- Spine_Block
`-- Jaw_Block

L_Arm_Config                     <- network node (the options)
Spine_Config
Jaw_Config

Asset Name_Grp                   <- the rig the build produces
|-- Ctrl_Grp
|-- Rig_Grp
|   |-- Bind_Joints_Grp
|   |-- Bind_Geo_Grp
|   |-- Miscellaneous_Grp
|   `-- Template_Grp
`-- Extra_Geo_Grp

That rig hierarchy comes from mt.build_baseA(), driven entirely by rig_setup.json. Change the JSON, every rig you build afterwards changes shape.

The mt object#

There is one entry point and it is deep. Mutant inherits straight down a chain, so a single instance exposes everything:

method resolution order
Mutant              main_mutant.py   version checks, GitHub updates
  \-- Modules_class   modules.py       blocks, guides, base rig, dev mode
      \-- Kinematics_class kinematics.py FK/IK, twist, ribbons, matrices
          \-- Tools_class   tools.py      controls, attrs, colour, nodes, JSON
ClassFilePublic methodsWhat lives there
Tools_classUtils/Rigging/tools.py61Controls and curve shapes, colour, attribute creation, offset groups, utility-node wiring, JSON read/write, matrix and mesh queries, push/corrective joints
Kinematics_classUtils/Rigging/kinematics.py36FK chains, IK chains and stretch, pole vectors, FK/IK switching, twist, ribbons, spline spines, wires, squash and bend, LODs, rivets
Modules_classUtils/Rigging/modules.py14create_block, guides, joint orientation, the base rig hierarchy, the name prompt, logging, dev mode
MutantUtils/Rigging/main_mutant.py6Local/online version compare, GitHub release check and in-place update
NoteThe full signature list, with every argument and default, is in the command wiki. It is generated from the source, so it cannot drift out of date.

nc, setup, curve_data#

One call returns all three config dictionaries. Call it at the top of every create_ and build_ function:

python
nc, curve_data, setup = mt.import_configs()

They are plain JSON under Mutant_Tools/config/, which means a studio can fork the naming convention without touching a line of rigging code.

nc - naming conventions#

Never hardcode a suffix. Build names from nc and the same block produces _Ctrl at one studio and _CTL at the next.

KeyValueKeyValue
nc['module']_Blocknc['ctrl']_Ctrl
nc['guide']_Guidenc['gimbal_ctrl']_Gimbal_Ctrl
nc['joint']_Jntnc['world_ctrl']_World_Ctrl
nc['joint_bind']_Bndnc['group']_Grp
nc['joint_end']_JntEndnc['locator']_Loc
nc['joint_twist']_JntTwistnc['curve']_Crv
nc['ik']_Ik_Jntnc['offset']_Offset
nc['fk']_Fk_Jntnc['root']_Root
nc['left']L_nc['auto']_Auto
nc['right']R_nc['null']_Null
nc['center']C_nc['follicle']_Fol
nc['geo']_Geonc['skin_cluster']_Skin

Utility nodes have entries too - nc['multiplyDivide'], nc['condition'], nc['blend'], nc['remap_value'], nc['reverse'], nc['unitConversion'], nc['distance'] - so even the plumbing in a rig reads consistently.

setup - rig defaults#

KeyDefaultUsed for
setup['base_groups']{geometry: Extra_Geo, control: Ctrl, rig: Rig}Top level of every rig
setup['rig_groups']{bind_joints, bind_geo, misc, template}Children of Rig_Grp
setup['main_ctrl_grp']Rig_CtrlGroup parented under the gimbal control
setup['twist_axis']XDefault aim axis for twist and limbs
setup['secondaryAxisOrient']zupJoint orientation up axis
setup['ik_fk_method']blendblend or constraint switching
setup['left_color'] / right_colorblue / redSide colouring
setup['main_color']lightBlueDefault control colour
setup['fk_ctrl']circlePointInDefault FK shape
setup['ik_ctrl'] / pv_ctrl']cube / sphereDefault IK and pole-vector shapes
setup['stretch_default']1Stretch on by default
setup['volume_preservation']0.5Squash amount on stretchy limbs

curve_data - the shape library#

44 named shapes, stored as raw CV positions and degree. Pass the name to mt.curve(), mt.controller() or mt.change_curve_shape():

2dArrow · 3dArrow · CircleDoubleArrow · WrapperThing · chair · circleDoublePointIn · circleDoublePointOut · circlePointIn · circlePointOut · circlePointUp · circleX · circleY · circleZ · circle_point · cog · cross · cube · cubePlus · curveArrow · cylinder · feet · gear · halfCircle · hand · happyFace · hexagon · locator · mover · octagon · pin_cube · pringle · pringle_point · rectangle · root · roundMover · sphere · square · squarePointUp · squareSmooth · sun · trapezoid · triangle · vis · wheel

Anatomy of a block#

A block is a folder under Blocks/<category>/ holding four files:

folder layout
Blocks/008_Props/01_Single_FK/
|-- 01_Single_FK.json          <- launcher, never versioned
|-- 01_Single_FK_v001.json     <- the versioned copy
|-- exec_single_fk.py          <- legacy alias
`-- exec_single_fk_v001.py     <- the implementation

The launcher JSON keeps a stable filename and points at whichever version is live. That indirection is what lets an old scene keep rebuilding after you ship a v002.

01_Single_FK.json
{
    "Name":         "Single_FK",
    "Description":  "This will create a Single FK Ctrl + Joint",
    "Icon":         "Bone.png",
    "Enable":       "True",
    "python_file":  "exec_single_fk_v001.py",
    "import":       "import exec_single_fk_v001",
    "imp.reload":   "reload(exec_single_fk_v001)",
    "exec_command": "exec_single_fk_v001.create_single_fk_block()",
    "build_command":"exec_single_fk_v001.build_single_fk_block()",
    "attrs": {
        "CtrlType_enum":   "sphere:cube:square:octagon",
        "CtrlSize_float":  "4",
        "CtrlColor_enum":  "lightBlue:blue:white:purple",
        "Mirror_enum":     "False:True:Right_Only",
        "Gimbal_bool":     "True",
        "CreateJoint_bool":"True",
        "SetCtrlParentHierarchy_string": "Ctrl_Grp",
        "Help_string":     "Overview: ...  How To Use: ..."
    }
}

The attrs dictionary and its type suffixes#

mt.create_block() walks attrs and turns each key into a real Maya attribute on the config node. The suffix picks the type, and the suffix is stripped from the attribute name - CtrlSize_float becomes .CtrlSize.

SuffixBecomesValue in JSONRead it back with
_stringstring attribute"Ctrl_Grp"cmds.getAttr(cfg + '.Name')
_enumenum attribute"a:b:c" (colon separated)cmds.getAttr(cfg + '.Name', asString=True)
_floatinteger, min 1, max 20"4"cmds.getAttr(cfg + '.Name')
_boolboolean attribute"True"cmds.getAttr(cfg + '.Name')
Trap

_float does not create a float. It calls new_attr_interger(min=1, max=20, default=int(value)), so you get an integer clamped between 1 and 20. A control size of 4.5 is impossible and a twist count of 30 silently clamps to 20. If you need a real float, add it yourself with mt.new_attr() after create_block returns.

Sharp edge

The type is chosen with if 'string' in attr, a substring test, not a suffix test, and it is checked in the order string, enum, float, bool. So an attribute you name UseStringy_bool contains string and quietly becomes a string attribute. Keep the type word out of the descriptive part of the name.

What create_block gives you#

python
block, config = mt.create_block(
    name='L_Arm',
    icon='Limb',                 # resolves to Mutant_Tools/Icons/Limb.png
    attrs=module['attrs'],
    build_command=module['build_command'],
    import_command=module['import'],
)
# block  -> 'L_Arm_Block'   a dagContainer parented under 'Mutant_Build'
# config -> 'L_Arm_Config'  a network node holding every option

On top of your own attributes, the config node always carries four more:

AttributeLockedPurpose
precodenoPython (or MEL) run before this block builds
Import_CommandyesThe import ... line the builder execs
Build_CommandyesThe call the builder evals to build this block
postcodenoPython (or MEL) run after this block builds
Note

precode and postcode are the escape hatch. A rigger who needs one odd fix on one asset can type it straight onto the block instead of forking your code. Both are exec'd, and if that raises, the builder falls back to mel.eval - so legacy MEL snippets keep working.

The build lifecycle#

Pressing Build walks the blocks under Mutant_Build in outliner order and runs the same seven steps on each. Reordering blocks in the outliner reorders the build - that is the dependency system.

AutoRigger build loop, simplified
for block in blocks:                      # outliner order, top to bottom
    cmds.select(block)
    config = config_of(block)

    exec(config.Import_Command)           # import exec_single_fk_v001
    exec(reload_command)                  # reload(exec_single_fk_v001)

    cmds.select(block)
    exec(config.precode)                  # falls back to mel.eval on error

    cmds.select(block)
    recipe = eval(config.Build_Command)   # <- your build_*() runs here
    recipes[block_name] = recipe          # return value is kept

    cmds.select(block)
    exec(config.postcode)
Do this

Notice cmds.select(block) before every phase. That is the calling convention. Your build_*() takes no arguments; it finds its own block with cmds.ls(sl=True). Always guard it - the selection can still be empty if someone calls your function by hand.

the guard every build function needs
def build_my_thing_block():
    nc, curve_data, setup = mt.import_configs()
    mt.check_is_there_is_base()

    selection = cmds.ls(sl=True) or []
    if not selection:
        cmds.warning('Select a block to build.')
        return

    block = selection[0]
    if not cmds.objExists(block):
        cmds.warning('Block does not exist: {}'.format(block))
        return

The return value is not thrown away#

Whatever build_*() returns is stored in the builder's recipe dictionary under the block's name. Return a dict of the nodes you created and a later block can look them up instead of guessing at string names.

python
def build_my_thing_block():
    ...
    return {
        'ctrl': ctrl,
        'joint': jnt,
        'bind_joint': bind,
        'root': root,
    }

Deferring a block#

Two optional boolean attributes on the config change when a block runs:

AttributeEffect
RunBeforeBuildBlock is pulled out of the normal pass and run first
RunAfterBuildBlock is deferred and run once every other block is done
Note

When either is on, the builder skips that block's precode and postcode during the main pass. Put the work in the build function, not in the code attributes, for any block that defers.

check_is_there_is_base#

First line of every build function. It looks for the base rig hierarchy and calls mt.build_baseA() to create it if missing, so a block can never build into an empty scene and leave nodes at the root.

python
mt.check_is_there_is_base()   # default base='BaseA'

Write your first block#

A complete, working block - a single FK control with an optional joint. Drop the folder into Blocks/008_Props/ and it appears in the AutoRigger with no registration step: the UI scans the folders.

1. The JSON#

99_Beacon.json
{
    "Name":          "Beacon",
    "Description":   "A single control with an optional bind joint",
    "Icon":          "Bone.png",
    "Enable":        "True",
    "python_file":   "exec_beacon_v001.py",
    "import":        "import exec_beacon_v001",
    "imp.reload":    "reload(exec_beacon_v001)",
    "exec_command":  "exec_beacon_v001.create_beacon_block()",
    "build_command": "exec_beacon_v001.build_beacon_block()",
    "attrs": {
        "CtrlType_enum":  "sphere:cube:circleY:locator",
        "CtrlSize_float": "4",
        "CtrlColor_enum": "yellow:blue:red:lightBlue",
        "CreateJoint_bool": "True",
        "SetParent_string": "Ctrl_Grp",
        "Help_string": "Overview:\n  One control, one optional joint.\n\nFields:\n- CtrlType: the shape.\n- CtrlSize: 1-20.\n- CreateJoint: also make a bind joint."
    }
}
Note

Help_string is what the artist reads in the AutoRigger's help panel. Every shipped block has one. Write it for the person placing guides at 11pm, not for yourself.

2. The create function#

create_ runs when an artist adds the block. It must be cheap and build nothing but the block, its config and its guides.

exec_beacon_v001.py
import os, json
from pathlib import Path
from maya import cmds

import Mutant_Tools
from Mutant_Tools.Utils.Rigging import main_mutant
mt = main_mutant.Mutant()

TAB_FOLDER = '008_Props'
PYBLOCK_NAME = 'exec_beacon'


def _module():
    path = os.path.join(os.path.dirname(__file__), '99_Beacon.json')
    with open(path) as handle:
        return json.load(handle)


def create_beacon_block(name='Beacon'):
    nc, curve_data, setup = mt.import_configs()
    module = _module()

    name = mt.ask_name(text=name)
    if not name:
        cmds.warning('Cancelled.')
        return ''

    if cmds.objExists('{}{}'.format(name, nc['module'])):
        cmds.warning('Name already exists.')
        return ''

    block, config = mt.create_block(
        name=name,
        icon='Bone',
        attrs=module['attrs'],
        build_command=module['build_command'],
        import_command=module['import'],
    )

    # the guide the artist positions
    guide = cmds.spaceLocator(n=name + nc['locator'])[0]
    cmds.parent(guide, block)

    cmds.select(block)
    print('{} created.'.format(name))

3. The build function#

build_ reads the config, reads the guide, and produces rig. Every scene operation is guarded, every name comes from nc, and the new attribute is read through attributeQuery so a scene saved before you added it still builds.

exec_beacon_v001.py
def build_beacon_block():
    nc, curve_data, setup = mt.import_configs()
    mt.check_is_there_is_base()

    selection = cmds.ls(sl=True) or []
    if not selection:
        cmds.warning('Select the Beacon block to build.')
        return

    block = selection[0]
    name = block.replace(nc['module'], '')
    config = '{}_Config'.format(name)

    if not cmds.objExists(config):
        cmds.warning('No config for {}'.format(block))
        return

    guide = '{}{}'.format(name, nc['locator'])
    if not cmds.objExists(guide):
        cmds.warning('Guide missing: {}'.format(guide))
        return

    # ---- read options, every one defensively --------------------
    shape = cmds.getAttr('{}.CtrlType'.format(config), asString=True)
    size = cmds.getAttr('{}.CtrlSize'.format(config))
    color = cmds.getAttr('{}.CtrlColor'.format(config), asString=True)

    make_joint = True
    if cmds.attributeQuery('CreateJoint', node=config, exists=True):
        make_joint = cmds.getAttr('{}.CreateJoint'.format(config))

    parent_to = setup['base_groups']['control'] + nc['group']
    if cmds.attributeQuery('SetParent', node=config, exists=True):
        wanted = cmds.getAttr('{}.SetParent'.format(config))
        if wanted and cmds.objExists(wanted):
            parent_to = wanted

    # ---- build ---------------------------------------------------
    ctrl = mt.curve(input=guide, type=shape, rename=True, custom_name=True,
                    name=name + nc['ctrl'], size=size)
    mt.assign_color(input=ctrl, color=color)

    root = mt.root_grp(input=ctrl)[0]

    # root_grp reparents ctrl, so the old DAG path can be stale
    ctrl = cmds.listRelatives(root, children=True, type='transform')[0]
    mt.match(root, guide, t=True, r=True)

    if cmds.objExists(parent_to):
        cmds.parent(root, parent_to)

    jnt = None
    if make_joint:
        cmds.select(clear=True)
        jnt = cmds.joint(n=name + nc['joint_bind'])
        mt.match(jnt, ctrl, t=True, r=True)
        cmds.parentConstraint(ctrl, jnt, mo=True)

        bind_grp = setup['rig_groups']['bind_joints'] + nc['group']
        if cmds.objExists(bind_grp):
            cmds.parent(jnt, bind_grp)

    print('Built {}'.format(block))
    return {'ctrl': ctrl, 'root': root, 'joint': jnt}

Controls, shapes, colour#

Two ways to make a control#

mt.controller() is the modern one: it makes the curve, colours it, adds a gimbal child and a world offset in a single call. mt.curve() is the older, lower-level one and is still what most shipped blocks use, because it can convert an existing guide in place.

python
# modern: one call, gimbal and world offset included
ctrl = mt.controller(input='', name='Hand', shape='hand',
                     color='blue', size=4, gimbal=True, world=True)

# classic: turn a guide into a control, keeping its transform
ctrl = mt.curve(input=guide, type='cube', rename=True, custom_name=True,
                name=joint.replace(nc['joint'], nc['ctrl']), size=size)
mt.assign_color(input=ctrl, color='blue')
root = mt.root_grp(input=ctrl)[0]

Offset groups#

mt.root_grp() inserts zeroed groups above a node, keeping its world transform and its place in the hierarchy. It returns a list.

CallCreates
mt.root_grp(input=ctrl)Hand_Ctrl_Offset_Grp
mt.root_grp(input=ctrl, autoRoot=True)Hand_Ctrl_Root_Grp and Hand_Ctrl_Auto_Grp
mt.root_grp(input=ctrl, custom=True, custom_name='SdkBuffer')Hand_CtrlSdkBuffer_Grp
Trap

Two things bite here. First, calling it twice with defaults tries to create the same name twice - always pass custom=True, custom_name='...' when a control gets more than one offset. Second, it reparents the node, so any DAG path you were holding may now be stale. Re-fetch the child from the returned group, exactly as the shipped Single_FK block does.

python
root = mt.root_grp(input=ctrl)[0]
ctrl = cmds.listRelatives(root, children=True, type='transform')[0]   # refresh

Colour#

mt.assign_color() takes ten names and sets Maya's index override. mt.assign_color_rgb() takes RGB or HSV. mt.smart_assign_color() picks by side from the name.

NameIndexNameIndexNameIndex
red13blue6white16
purple9green14lightBlue18
yellow17pink20grey1
orange21

The convention the shipped blocks follow, driven from setup:

python
if side_guide.startswith(nc['right']):
    color = setup['right_color']        # red
elif side_guide.startswith(nc['left']):
    color = setup['left_color']         # blue
else:
    color = setup['center_color']       # yellow

mt.assign_color(input=ctrl, color=color)

Attributes#

Use the mt helpers rather than cmds.addAttr. They keep ordering, keyability and locking consistent across every rig the system produces.

CallMakes
mt.new_attr(input, name, min, max, default, keyable)A double
mt.new_attr_interger(input, name, min, max, default)An integer
mt.new_enum(input, name, enums='Hide:Show', default)An enum
mt.new_boolean(input, name, dv='True')A boolean
mt.string_attr(input, name, string)A string, for storing data on the rig
mt.line_attr(input, name, lines=10)A separator row in the channel box
mt.hide_attr(input, t, r, s, v, rotate_order, show)Hides or reveals channels
mt.create_proxy_attr(original_attr, output_node, ...)A proxy of an attribute elsewhere
mt.change_default(attr, default)Changes an existing attribute's default
python
# a roll attribute with a sane range
attr = mt.new_attr(input=ik_attrs_shape, name='Roll', min=-100, max=100, default=0)

# a visibility switch
mt.new_enum(input=ctrl, name='Gimbal', enums='Hide:Show')

# a labelled divider, then hide what animators must not touch
mt.line_attr(input=ctrl, name='Extras')
mt.hide_attr(input=jaw_ctrl, s=True, v=True)

Wiring values without spaghetti#

Rather than hand-building utility nodes, the mt helpers name them from nc and connect both sides in one call.

python
# invert a value into a rotation limit
mt.connect_md_node(in_x1=up_limit, in_x2=-1, mode='multiply',
                   out_x=upper_pivot_joint + '.minRotLimit.minRotZLimit')

# remap one range onto another
mt.connect_remap_value(input_value, output_value, value=0)

# insert an addDoubleLinear between two already-connected plugs
mt.replace_connection_with_doublelinear(input=node, attr='translateY')

# matrix parenting instead of a constraint
mt.parent_matrix(this=driver, that=driven, translate=True, rotate=True, scale=False)
Note

mt.create_add_double_linear() and mt.create_mdl_compat() exist because Maya renamed these node types between versions. Use them instead of cmds.createNode('addDoubleLinear') if your rigs have to open in more than one Maya release.

FK, IK, twist, ribbons#

The kinematics layer is where the time goes. These calls produce complete, working setups - controls, switches, stretch and all.

CallProduces
mt.fk_chain(input, size, color, curve_type, scale, twist_axis, world_orient)An FK control chain over selected joints
mt.simple_ik_chain(start, end, size, color, ik_curve, pv_curve, pv)An IK handle with control and pole vector
mt.simple_fk_ik(start, mid, end, size, color, mode, twist_axis)A three-joint FK/IK setup with a switch
mt.twist_fk_ik(start, mid, end, twist_amount=6, ...)The same plus twist joints - a full limb
mt.streatchy_ik(ik, ik_ctrl, top_ctrl, pv_ctrl, attrs_location, axis)Stretch nodes on an existing IK chain
mt.base_spline(start, end, size, name='Spine', amount=5)An IK/FK spline spine
mt.advance_twist(start, end, axis, amount=4, mode='up', driver='')Distributed twist joints reading real rotation
mt.spline_twist(start, end, axis, amount, mode, right_side)Spline-driven twist
mt.basic_ribbon(start, end, divisions=5, ctrl_type='circleY')A follicle ribbon with controls
mt.ribbon_between(start, end, divisions, ...)A ribbon spanning two existing nodes
mt.curve_to_ribbon(curve, amount=5, direction='V')A ribbon built along an existing curve
mt.pole_vector_placement(bone_one, bone_two, bone_three, back_distance)The mathematically correct pole-vector position
mt.joints_middle(start, end, axis, amount=4, name='Twist')Evenly spaced joints in a chain
mt.blend_between(ctrl, blends, attr_position, attr_name)Space-switch blend groups and locators
mt.bend_and_squash(name, geo, parent_grp, squash_enabled, bend_enabled)Squash and bend deformers with controls
mt.create_dynamic_fk(joints)A dynamic FK chain
mt.dinamic_pivot(input, size)A movable pivot rig on a control
mt.rivets_ctrls(geometry, selection_ctrls)Controls stuck to geometry
Note

Most of these default their axis and shapes from setup, so calling mt.fk_chain(input=joints) with nothing else already matches the studio's house style. Only pass arguments you actually want to override.

Mirroring#

Mirroring is a group-level trick, not a per-node one. mt.mirror_group() wraps a hierarchy in a group with a negative scale, so the whole branch flips at once and the maths stays exact.

Shipped blocks expose a Mirror_enum with three states and handle it after the controls exist:

python
mirror = cmds.getAttr('{}.Mirror'.format(config), asString=True)

if mirror == 'Right_Only':
    clean_ctrl_grp = mt.mirror_group(clean_ctrl_grp, world=True)

elif mirror == 'True':
    if side_guide.startswith(nc['right']):
        clean_ctrl_grp = mt.mirror_group(clean_ctrl_grp, world=True)
ValueMeaning
FalseBuild exactly what the guides describe
TrueBuild both sides, auto-prefixing L_ where needed
Right_OnlyMirror the built result onto the right side only
Trap

Mirror after you create controls and before you rely on their world positions, and re-apply constraints afterwards. A constraint made before the mirror group is inserted will fight the negative scale.

Block versioning#

This is not optional and it is the reason old rigs keep rebuilding. Implementation files carry a version; the launcher JSON does not.

naming
exec_mouth_v001.py        003_Mouth_v001.json      <- frozen, never edited again
exec_mouth_v002.py        003_Mouth_v002.json      <- your new work
                          003_Mouth.json           <- launcher, repointed to v002

Shipping a new version:

  1. Copy exec_x_v001.py and NN_X_v001.json to _v002.
  2. Make your changes only in the v002 files.
  3. Repoint the launcher JSON's python_file, import, imp.reload, exec_command and build_command at v002.
  4. Leave v001 on disk, untouched, forever.
Note

A scene saved last year has exec_mouth_v001.build_mouth_block() baked into its config node's locked Build_Command string. If you deleted or rewrote v001, that scene no longer rebuilds. Keeping old versions is what makes the promise 'this rig can always be rebuilt' true.

Adding an attribute to an existing block#

Old config nodes in saved scenes will not have your new attribute. An unguarded getAttr is a hard error mid-build.

python
# WRONG - explodes on every scene saved before this attr existed
independent_scale = cmds.getAttr('{}.IndependentScale'.format(config))

# RIGHT - fall back to the JSON default
independent_scale = (
    cmds.attributeQuery('IndependentScale', node=config, exists=True)
    and cmds.getAttr('{}.IndependentScale'.format(config))
)

Traps that will bite you#

_float is an int, 1 to 20

The JSON suffix lies. Add a real float with mt.new_attr() after create_block if you need one.

Type detection is a substring test

'string' in attr, checked before enum, float and bool. Do not put a type word inside a descriptive attribute name.

root_grp invalidates DAG paths

It reparents the node. Re-fetch the child from the returned group before you use it.

root_grp twice clashes

Default suffixes collide. Pass custom=True, custom_name='...' for the second.

Build order is outliner order

There is no dependency graph. If block B needs block A, A must sit above it.

Your build function takes no arguments

It reads cmds.ls(sl=True). The builder selects the block for you - guard for the empty case anyway.

New attrs break old scenes

Always guard with cmds.attributeQuery(..., exists=True) and fall back to the JSON default.

Never delete an old block version

Saved scenes hold the versioned call string in a locked attribute.

precode falls back to MEL

If exec raises, the builder tries mel.eval. A Python syntax error can surface as a confusing MEL error.

Mutant() writes to the scene

Constructing it creates a Mutant_Tools node. Expect it in clean-scene checks and asset publishes.

Pipeline integration#

Building without the UI#

Nothing about a block needs the AutoRigger window. Call the same functions yourself and the same rig comes out - which is what makes batch rebuilds and CI checks possible.

batch rebuild
from maya import cmds
from Mutant_Tools.Utils.Rigging import main_mutant

mt = main_mutant.Mutant()
nc, curve_data, setup = mt.import_configs()

cmds.file('/jobs/show/asset/rig_blocks.ma', open=True, force=True)

blocks = cmds.listRelatives('Mutant_Build', children=True, type='transform') or []

for block in blocks:
    name = block.replace(nc['module'], '')
    config = '{}_Config'.format(name)
    if not cmds.objExists(config):
        continue

    import_command = cmds.getAttr('{}.Import_Command'.format(config))
    build_command = cmds.getAttr('{}.Build_Command'.format(config))

    exec(import_command)
    cmds.select(block)
    eval(build_command)

cmds.file(rename='/jobs/show/asset/rig_built.ma')
cmds.file(save=True, type='mayaAscii')
Trap

Order matters and listRelatives gives you outliner order, which is what you want. Do not sort that list.

Version and update checks#

python
mt.get_local_version()          # from config/version.json
mt.get_online_version()         # scrapes mutanttools.com/current_version/
mt.get_github_latest_release()  # public GitHub API, no auth needed
mt.check_for_updates(silent=False)
mt.check_dev_mode()             # True while config/version.json has dev_mode on
mt.toggle_dev_mode()
Note

Turn dev mode on while you develop. It suppresses the update prompt, so your local edits are never overwritten by an auto-update mid-session.

Reading and writing rig data#

python
mt.write_json(path, json_file, data)
data = mt.read_json(path, json_file)

The Utils/IO package builds on this for skin weights (NgSkin_Data), control shapes (Ctrl_Data) and guide positions (Guide_Data) - which is how 009_Data/01_Load_Skin and 02_Load_Ctrls reapply data as ordinary blocks in the build order.

Using AI on this codebase#

Mutant Tools ships machine-readable coding rules so an assistant writes blocks that match the house pattern instead of generic Maya Python. They live in the repo at Docs/AI_MT_COMMAND_RULES.md and Docs/AI_MT_COMMAND_TUTORIAL.md, and there is a llms.txt at the site root.

Paste this at the start of a session:

initial prompt
You are coding inside the Mutant_Tools Maya rigging workspace.

Follow these rules strictly:
1) Use the Mutant API entry point:
   from Mutant_Tools.Utils.Rigging import main_mutant
   mt = main_mutant.Mutant()
2) In block functions, always import configs with:
   nc, curve_data, setup = mt.import_configs()
3) In build functions, always validate base with:
   mt.check_is_there_is_base()
4) Preserve existing block architecture and naming patterns
   (create_<block>_block / build_<block>_block).
5) Before Maya operations, guard with cmds.objExists and
   cmds.attributeQuery(..., exists=True).
6) If creating offset/root helper groups repeatedly, use
   mt.root_grp(input=node, custom=True, custom_name='UniqueSuffix')
   to avoid name clashes.
7) If deleting/rebuilding constraints, cache constraint type + targets
   and restore deterministically with mo=True.
8) Make minimal, focused edits only; do not refactor unrelated code.
9) Use cmds.warning for recoverable issues and concise prints for success.
10) Keep changes compatible with the existing Mutant_Tools style
    (the codebase mixes Python 2 and 3 patterns).
11) When adding a new attribute to a block JSON, always guard its getAttr
    with cmds.attributeQuery(..., exists=True) so old saved rigs still build.
12) Block versioning is required: create versioned exec/json files and keep
    the launcher JSON pointing at the active version.

When requirements are ambiguous, choose the simplest solution consistent
with existing blocks.
Note

Add a scope line for narrow tasks: “Implement only the requested body section. Do not add leg/finger/spine logic.” Without it, assistants reliably over-build.

Where to go next#

Command wiki

Every mt method with its full signature, plus all 133 shipped blocks and their options. Open the wiki

Source

The whole system is readable. RenderDeMartes/Mutant_Tools

Auto rigger

What the blocks feel like from the artist side. Maya auto rigger

Learn

Workflow walkthroughs and production examples. Learn

For riggers

The non-Python tour of the same system. Rigger guide

Free assets

Rigs and tools to pull apart. Free assets

Build something with it

Mutant Tools is free to download and the source is public. If you build a block worth sharing, or hit something this page did not answer, get in touch.

Generated from RenderDeMartes/Mutant_Tools at 2dc3eae · 18 September 2026