Multiple Duplication

import maya.cmds as mc

selected = mc.ls (sl=1, fl=1)

try:
    objA = selected[0]
    objB = selected[1]
except:
    print "Error! Select two objects."

positionA = mc.xform (objA, q=1,  ws=1, t=1)
positionB = mc.xform (objB, q=1,  ws=1, t=1)

def dupMove (obj, moveX, moveY, moveZ):
    newObj = mc.duplicate (obj)
    mc.move (moveX, moveY, moveZ, newObj, r=1)

result = cmds.promptDialog(
                title='Multiple Duplicate',
                message='Input number of duplications',
                button=['OK', 'Cancel'],
                defaultButton='OK',
                cancelButton='Cancel',
                dismissString='Cancel')

if result == 'OK':
        duplications = cmds.promptDialog(query=True, text=True)
try:
    dupX = (positionA[0]-positionB[0])/(int(duplications)+1)
    dupY = (positionA[1]-positionB[1])/(int(duplications)+1)
    dupZ = (positionA[2]-positionB[2])/(int(duplications)+1)
    for each in xrange(int(duplications)):
        print each
        moveX = (dupX*(each+1))*(-1)
        moveY = (dupY*(each+1))*(-1)
        moveZ = (dupZ*(each+1))*(-1)
        print moveX
        dupMove (objA, moveX, moveY, moveZ)
except:
    print "Error! Enter an integer."
mc.select (selected)
Advertisements