Mirroring/adding Blendshapes with Python question

python
maya

#1

So I know there is a bunch of mirror blendshapes codes in Mel and Python out there, but I wanted to try my hand at making my own. For starters create an object: any object, so long as you name it “faceMask” you’re good. After that boot up the script, set a name prefix for your blendshapes (I named it Test1), tick “Create Mask Blend” then load “faceMask” simply by selecting it and hitting “Load Main Object”: then when you hit “Mirror Blendshapes” you should get an editable mirror. Simply turn on the blendshapes in the “faceBlend” blendshapes category, play around with the left shape and tada! you have your first blendshape

Now where I run into 2 problems afterwards however, is when I want to create a second Blendshape: Let say I name my second blendshape “Test2” then check “Add to Mask Blend” it creates everything else just fine: but I want it to add any future blendshapes to the “faceBlend” blendshape node and no matter what naming conventions or code variations I type it just fails and doesn’t add the Blendshapes.

The second problem I run into is I want the “maxDistance” attributes for the wrap to be be created with a default of 0 instead of 1: but no matter what I look up apparently there is no answer for that.

I just want to know: whats the python code for adding blendshapes to an existing blendshape node and what is the code for setting the maxDistance of a wrap deformer?

I’ll post the code below for anyone willing to take a swing at it, thank you for your help and time.

import maya.cmds as cmds
from functools import partial

if cmds.window(“dumWin”, exists =True):
cmds.deleteUI(“dumWin”, window=True)

myWindow = cmds.window(“dumWin”,t=‘DS Face Blendshape Builder’, toolbox=True)
column = cmds.columnLayout(adj=True)

nodeNum1 = 0
nodeNum2 = 0

def nameBlend(*args):
cmds.textField(‘name_text’, e = True)

def SetSource(*args):
global source
selection = cmds.ls(sl=True)

if len(selection) != 1:
    source = ""
    print( "Select one object" )
else:
        source = selection[0]
        
cmds.textField('source_text', e=True, text = source)

def mirrorBlendShape(*args):
namePref = cmds.textField(‘name_text’, q=True, text=True)
L_Shape = cmds.textField(‘source_text’, q=True, text=True)
R_Shape = cmds.textField(‘source_text’, q=True, text=True)
W_Shape = cmds.textField(‘source_text’, q=True, text=True)

cmds.duplicate(name = 'L_' + namePref + '_Blend')
cmds.duplicate(name = 'R_' + namePref + '_Blend')
cmds.duplicate(name = namePref + '_Wrap')

cmds.blendShape ('L_' + namePref + '_Blend', namePref + '_Wrap',en=1,w=(0, 1))
cmds.scale(-1,1,1, namePref + '_Wrap')

cmds.move(-3,3,0, 'L_' + namePref + '_Blend')
cmds.move(-3,0,0, 'R_' + namePref + '_Blend')
cmds.move(-3,0,0, namePref + '_Wrap')

cmds.group('L_' + namePref + '_Blend','R_' + namePref + '_Blend',namePref + '_Wrap',  n= namePref + '_Grp')

cmds.select('R_' + namePref + '_Blend', namePref + '_Wrap')
cmds.CreateWrap()
#cmds.setAttr(".maxDistance", 0.0)


if nodeNum1 ==1:
    cmds.select('L_' + namePref + '_Blend','R_' + namePref + '_Blend', 'faceMask')
    cmds.blendShape(n= 'faceBlend')
    cmds.select('faceMask')
    
if nodeNum2 ==2:
    cmds.select('L_' + namePref + '_Blend', 'R_' + namePref + '_Blend', 'faceMask')

    cmds.blendShape(faceBlend, edit = True, target =(mesh, target_index, corrective, 1))
    
    cmds.select('faceMask')

def UI():
cmds.columnLayout
cmds.text(‘Set blend name prefix’)
cmds.textField(‘name_text’, editable = True)
cmds.radioCollection()
cmds.radioButton (label=‘Create Mask Blend’, onCommand = “nodeNum1 = 1”, offCommand = “nodeNum1 = 0” )
cmds.radioButton (label=‘Add to Mask Blend’, onCommand = “nodeNum2 = 1”, offCommand = “nodeNum2 = 0” )

cmds.textField('source_text', editable = False)
cmds.button( label="Load Main Object", c = SetSource)
cmds.separator ( style = 'in')
cmds.button( label='Mirror Blendshapes', c = mirrorBlendShape)

cmds.setParent('..')

UI()
selection = cmds.ls(sl=True)

cmds.showWindow(myWindow)