### 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 = cmd.ls(os=True, fl = True)
ob = cmd.ls(o=True, sl=True)
num = []
out = []
edges = []
joints = []
for one in sel:
strip = re.search(r"\[([0-9]+)\]", one)
num.append(strip.group(1))
size = len(num)
if (size):
if size == 1:
edges = cmd.polySelect(edgeRing=(int(num)), ns = True)
if size == 2:
edges = cmd.polySelect(edgeRingPath=(int(num), int(num)), ns = True)
if size > 2:
edges = num
for one in edges:
cmd.select(ob)
cmd.polySelect(elb=int(one))
clust = cmd.cluster(n = 'poo#')
cmd.select(clear=True)
posi = cmd.getAttr(clust+'HandleShape.origin')
if c:
points = points + ('-p %s %s %s ' %(posi, posi, posi))
if j:
joints.append(cmd.joint(p = (posi, posi, posi)))
cmd.delete (clust)
if c:
out.append(mel.eval(points))
if j:
for i in reversed(range(1, len(edges))):
cmd.parent(joints[i], joints[i-1])
cmd.joint(joints, e=True, oj = 'xyz', sao= 'zup', ch=True, zso=True)
cmd.joint(joints[-1],e=True, o =(0,0,0))
out.append(joints)
cmd.select(out)
else:
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. 