MakeCenterLine for Maya

Ever wanted to quickly draw a line in the center of a 3D object in Maya? Say you need to place a curve there or joints, or both. This short Python script will let you create a curve or joints down the volumetric center of a mesh by way of an edge loop selection.

 The script has three functions, depending on what you select.
  • If you select one edge and run the script, it will generate a curve down the center of the object using all edge loops.
  • Select two edges, and it will generate a curve BETWEEN those two edge loops.
  • Select three or more edges, and it will generate a curve only using those selected edge loops (Good for heavy, redundant geo)
There are two flags, make centerline(0,1) creates a joint chain, (1,0) makes a NURBS curve and (1,1) makes both.

import maya.cmds as cmd
import maya.mel
import re

def makeCenterLine(c=1, j=1):
    #track selection order must be ON for this to work
    points = 'curve -d 3 '
    sel =, fl = True)
    ob =, sl=True)
    num = []
    out = []
    edges = []
    joints = []
    for one in sel:
        strip ="\[([0-9]+)\]", one)
    size = len(num)
    if (size):
        if size == 1:      
            edges = cmd.polySelect(edgeRing=(int(num[0])), ns = True)
        if size == 2:      
            edges = cmd.polySelect(edgeRingPath=(int(num[0]), int(num[1])), ns = True)
        if size > 2:
            edges = num
        for one in edges:
            clust = cmd.cluster(n = 'poo#')
            posi = cmd.getAttr(clust[0]+'HandleShape.origin')
            if c:
                points = points + ('-p %s %s %s ' %(posi[0][0], posi[0][1], posi[0][2]))
            if j:
                joints.append(cmd.joint(p = (posi[0][0], posi[0][1], posi[0][2])))
            cmd.delete (clust[0])
        if c:
        if j:
            for i in reversed(range(1, len(edges))):
                cmd.parent(joints[i], joints[i-1])
            cmd.joint(joints[0], e=True, oj = 'xyz', sao= 'zup', ch=True, zso=True)
            cmd.joint(joints[-1],e=True, o =(0,0,0))
        print "Nothing is selected"
makeCenterLine(0, 1)


  1. just copy-paste the script? does not work for me. maya 2017.

    1. makeCenterLine(1, 1)
      # Error: invalid syntax #

    2. Are you pasting into a python tab or a mel tab?

    3. It could be the formatting. Try downloading the script from here:


Post a Comment

Popular Posts