4/30/2014

Maya scripting - small steps with Mel and Python

Starting over again with scripting in Maya...I'll post here some of my scripts and maybe some handouts or interesting things I'll find out. As a start up I've bought this book - Maya Python for Games and Film.

Create offset nodes for selected objects V 1.0 - Python

Small, easy to create, but useful script. Done allready many times. I've needed to start with something simple. I learned here how to use lists and basic loop statement.
import maya.cmds as mc
sel= mc.ls(sl=True)
if sel:
    for i in range(len(sel)):
           offset= mc.group(em=True,n=(sel[i] + '_offset'))
           pcons= mc.pointConstraint(sel[i], offset)
           rcons= mc.orientConstraint(sel[i], offset)
           mc.delete(pcons, rcons)
           mc.parent(sel[i], offset)
           print 'Offset nodes for selected objects were created.',
else:
    print 'No object selected!!! Please select at least one object.',