1

# Brent Forrest’s Script Can Easily Find the Volumetric Center of an Object.

Ever wanted to quickly draw a line in the center of a 3D object in Maya? Let’s say you need to place a curve there or joints, or both. You could eyeball it, but Brent Forrest has a handy script solution. 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.

“This came from a help request on some forum – someone was asking if there was a quick way to draw a line down the center of a 3D mesh,” Forrest says. “The answer is “Yes if it has edge loops” – And here’s a useful python script for generating either NURBS curves, joint chains or both down the middle of an object with edge loops.” 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.

Check out MakeCenterLine here.

### 1 comment

1. #### Brent

Here’s the script with formatting (Also available from https://www.highend3d.com/maya/script/makecenterline-for-maya)

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[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:
cmd.select(ob)
cmd.polySelect(elb=int(one))
clust = cmd.cluster(n = ‘poo#’)
cmd.select(clear=True)
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:
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[0], e=True, oj = ‘xyz’, sao= ‘zup’, ch=True, zso=True)
cmd.joint(joints[-1],e=True, o =(0,0,0))
out.append(joints[0])
cmd.select(out)
else:
print “Nothing is selected”

makeCenterLine(0, 1)