-1

I'm trying to match positions of objects with similar names from different lists in my maya scene using python.

i.e In my scene there are 100's of big boxes ("Box_01_obj","Box_02_obj"...) and 100's of small boxes ("Box_01_obj_small", "Box_02_obj_small"...) and I'm trying to make those small boxes match big boxes location.

How could I do this using python?

1 Answers1

0
import maya.cmds as mc

for SmallBox in mc.ls("*_small"):
    BigBox = SmallBox.replace("_small","")
    if mc.objExists(BigBox):
        BigBoxPositionX = mc.getAttr(BigBox+".tx")
        mc.setAttr(SmallBox+".tx", BigBoxPositionX)
        
        BigBoxPositionY = mc.getAttr(BigBox+".ty")
        mc.setAttr(SmallBox+".ty", BigBoxPositionY)
        
        BigBoxPositionZ = mc.getAttr(BigBox+".tz")
        mc.setAttr(SmallBox+".tz", BigBoxPositionZ)

This will work, assuming that the boxes share the same parent, or are unparented. If not, you'll have to use a more complex align function or parent constrain the small boxes to the big ones and then remove the parent constraint.

mranim8or
  • 159
  • 2
  • 9