Results 1 to 4 of 4

Thread: [Maya][Python] ScriptJob Symmetry question

  1. #1
    integer PereBalsach's Avatar
    Join Date
    Apr 2015
    Location
    Barcelona
    Posts
    32

    Default [Maya][Python] ScriptJob Symmetry question



    Hi!
    Im trying to do a scriptjob to do a symmetry for the translation on the selected object.
    Im 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 its 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:
    Code:
    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)

  2. #2
    Technical Artist
    Join Date
    Jul 2008
    Location
    Austin, TX
    Posts
    673

    Default

    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.

  3. #3
    integer PereBalsach's Avatar
    Join Date
    Apr 2015
    Location
    Barcelona
    Posts
    32

    Default

    Its 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?

  4. #4
    Technical Artist
    Join Date
    Jul 2008
    Location
    Austin, TX
    Posts
    673

    Default

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •