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!
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)