top of page

Efficient Maya Python Script

Instancing and Snapping to Multiple Objects

Efficient Maya Python Script

'''This is a python script to be run under python in MAYA
make sure below points
1)select the object to be instanced and replaced before running
2)group the existing objects and rename as mainGoup
3)make sure no other constraints exist in the scene'''

import maya.cmds as cmds

#get the selected Object
emptyList = []
selectedObj = cmds.ls(selection=True)
finalSelectedObj = selectedObj[0]

#get the group
groupItems=cmds.listReleatives('mainGroup')

#collect the duplicated items of selected object and fill the empty list
for everyItem in groupItems:
check = cmds.duplicate(finalSelectedObj)
emptyList.append(check)

#for every item in group parent, orient, scale constraint each of duplicated items
for all, each in zip(groupItems, emptyList):
cmds.pointConstraint(all, each, mo=False)
cmds.orientConstraint(all, each, mo=False)
cmds.scaleConstraint(all, each, mo=False)

#delete all constraints
cmds.delete(all=True, constraints=True)

bottom of page