To be coherent with most of Maya's functions, I adopted the 'first selected matters' approach: first select the object whose shape will be instanced, then the ones that twill receive the new shape.
Execute the script and voilĂ !
### Instancer #############################################
### Vincent Schneider - 2015 ##############################
#First select the node whose shape will replace the others#
###########################################################
import maya.cmds as cmds
baseObjects = (cmds.ls(sl=True))
objNum = len(baseObjects)
if objNum > 1:
shapeObj = baseObjects[0]
objects = baseObjects[1:]
for baseObj in objects:
new = cmds.instance(shapeObj)
cmds.parent(new, baseObj)
oldShape = cmds.listRelatives(baseObj, shapes = True)
cmds.delete(oldShape)
shape = cmds.listRelatives(new, shapes = True)
cmds.parent (shape, baseObj, add = True, shape = True)
cmds.delete(new)
else:
cmds.confirmDialog( title='Nope!', message='At least two objects must be selected', button=['OK'] )
A bunch of freshly instanced objects adapting to their new shape |
No comments:
Post a Comment