top of page
Search

More Python Rigging - Mirroring Curves

  • jasondobra
  • May 23
  • 1 min read

Just a quick one: I recently i made this really small bit of code to mirror curves because this was missing in the autorigging software at work.


Utilizing the curve points that are displayable when you select components or control points of a curve. This can be found using the attribute editor under controls curves shape. You can then loop through their location in world space with a xform. That's basically it.


ree

I added a prefix condition to work on both sides, since i do most of my controls start in L_ and R_ respectively.


As usual if you have any questions. Reach out. Jase


import maya.cmds as cmds 

def mirror_shapes(curves):
    
    #here you can name your suffix
    left_side = 'L_'
    right_side = 'R_'
    
    for crv in curves:
        curve_shape = cmds.listRelatives(crv, shapes=True)[0]
        crv_pnts = cmds.getAttr(f'{curve_shape}.controlPoints[*]')
        for num, pnt in enumerate(crv_pnts):
            crv_pnt = cmds.xform(f'{curve_shape}.controlPoints[{num}]', q=True, t=True, ws=True)
            
            if curve_shape.startswith(left_side):
                opposite_shape = curve_shape.replace(left_side, right_side)
                cmds.xform(f'{opposite_shape}.controlPoints[{num}]', t=(-crv_pnt[0], crv_pnt[1], crv_pnt[2]), ws=True)
                
            else:
                opposite_shape = curve_shape.replace(right_side, left_side)
                cmds.xform(f'{opposite_shape}.controlPoints[{num}]', t=(abs(crv_pnt[0]), crv_pnt[1], crv_pnt[2]), ws=True)
            
    
if __name__ == "__main__":
    mirror_shapes(cmds.ls(sl=True, type='transform'))

 
 
 

Comments


bottom of page