[Maya][Python] ScriptJob Symmetry question

Hi!
I´m trying to do a scriptjob to do a symmetry for the translation on the selected object.
I´m using the attributeChange parameter on the scriptJob, and I should use 3 different scriptJobs to get the full symmetry working, one for each axis (x, y, z)
I think it´s quite dirty doing it this way right? Any ideas how can I tackle that?

Is there any attribute or way to create the script job for having more fast feedback? Instead of waiting the mouse to be released to get the viewport update, How can I create a realtime update in the viewport?

Thanks in advice guys! :slight_smile:

This is what I have so far:


import pymel.core as pm
import maya.cmds as cmds


class SymmetryPos(object):
    """

    """
    def __init__(self, obj=None):
        self.sourceObj = obj[0]
        print ('source object: ' + self.sourceObj)
        self._duplicateSourceObj()
        self.createScriptJob()
        
        
    def createScriptJob(self):
        print ('Object Mirrored: ' + self.targetObj[0])
        
        # create scriptjob for translate X
        self.scriptJobSymX = cmds.scriptJob(attributeChange=[str(self.sourceObj + '.translateX'), self.doSymmetry], killWithScene=True)
        

    def doSymmetry(self, axis=''):
        # gets the source object position
        self.sourcePos = pm.xform(self.sourceObj, query=True, piv=True, ws=True)
        
        # sets the mirrored position for the x component to the target object
        pm.xform(self.targetObj[0], ws=True, t=(self.sourcePos[0] * -1, self.sourcePos[1], self.sourcePos[2]))
            
            
    def _duplicateSourceObj(self):
        # duplicate the source object and move it to the mirrored position
        self.targetObj = pm.duplicate(self.sourceObj, name='target_obj')
        
        # gets the source object position
        print ('..................')
        print self.sourceObj
        print ('..................')
        self.sourcePosDup = pm.xform(self.sourceObj, query=True, piv=True, ws=True)
        
        # sets the target object new position
        pm.xform(self.targetObj[0], ws=True, t=(self.sourcePosDup[0] * -1, self.sourcePosDup[1], self.sourcePosDup[2]))

    def delScriptJob(self):
        # kill the script job
        cmds.scriptJob(k=self.scriptJobSymX, force=True)


selection = pm.ls(sl=True)
ob = SymmetryPos(selection)


maya has it’s own built in symmetry features… why invent the wheel?
also, you can always make an Instance of a model and flip it on one axis, and the instance will update in real time as you modify the original half.

It´s for building a pre-autorig skeleton and position the helpers in the right position to build the full skeleton. Do you think I can reuse the existing one form maya?

you can try Transfer Attributes set to Position. Maya also has a built-in Mirror Mesh feature as well.