Wednesday 29 April 2015

Instancer for Maya

I shared my instancer for Max not long ago, so while I'm at it I should share the one I wrote for Maya! It works pretty simply, by replacing the shape inside the object.

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

The script is also available here, info on how to use scripts in Maya can be found here.

No comments:

Post a Comment