Driven keys script issue

Driven keys script issue

ead1797
Contributor Contributor
396 Views
1 Reply
Message 1 of 2

Driven keys script issue

ead1797
Contributor
Contributor

Hello, I am having an error with my python script, where I am trying to attach my blendshapes to a control handle with the setdrivenkeys command. I am trying to figure out the code that attaches them.

Screenshot 2022-11-29 at 2.49.22 PM.png

 

import maya.cmds as mc

#BLENDSHAPES

mc.select ('ORIGINAL')
mc.blendShape ('ORIGINAL', name= 'faceBlends')

grp = mc.select ('Human*')
mc.select ('ORIGINAL', d= True)

obj = mc.ls (selection = True, tr= True)
print (obj)

num = 0
for item in obj:
    mc.blendShape ('faceBlends', e= True, t= ['ORIGINAL', num, item, 1.0])

    num = num + 1


#CREATE UI WINDOW
def createWin():
    if mc.window('Human', exists=True):
        mc.deleteUI('Human')
    mc.window('Human')
    mc.columnLayout(adjustableColumn=True)
    mc.button(l='Happy', c='Happy()')
    mc.button(l='Sad', c='Sad()')
    mc.button(l='Angry', c='Angry()')  
    mc.button(l='Shock', c='Shock()')    
    mc.showWindow('Human')
createWin()


menuName = "Extra"
mc.optionMenu( menuName, label='Extra')
mc.menuItem( label='EditFace', parent = menuName )
mc.button(l='OpenHandles', c='OpenHandles()')




#CTRLHANDLES
num = 0
sq= 'ctrlFrame' + str(num)
round= 'ctrlHandle' + str(num)

mc.curve (n= sq, d=1, p=[(0,1,0),(2,1,0),(2,0,0),(2,-1,0),(0,-1,0),(-2,-1,0),(-2,0,0),(-2,1,0), (0,1,0)])
mc.circle(n= round, nr= (0,0,1), r=1)
mc.transformLimits (tx= (-1,1), etx= (True,True),
                    ty= (0,0), ety= (True,True),
                    tz= (0,0), etz= (True,True))
                 
mc.group (round, sq, n = 'Controls')

#TEST1
#side = 0
#up = 0
#num = 0

#while up < 2:
  #while side < 2:
    #mc.select ('Controls')
    #mc.setAttr ('Controls.ty', up*2)
   # mc.setAttr ('Controls.tx', side*2)

    
#    side += 1
#    num += 1
#  side = 0
#  up += 1

#HARDCODED
 
#mc.select ('Angry')
#mc.duplicate (n= 'Happy')
#mc.move (4.5, 0, 0)
#mc.duplicate (n= 'Sad')
#mc.move (4.5, 4.5, 0)
#mc.duplicate (n= 'Shock')
#mc.move (0, 4.5, 0)

        


mc.setDrivenKeyframe (at= 'ctrlHandle0' + '.tx', cd= 'Human1', dv = 0, v= 0)

 

 

 

 

397 Views
1 Reply
Reply (1)
Message 2 of 2

Kahylan
Advisor
Advisor

Hi!

I'm assuming that you want your controls translateX to control your "Human1" target. So the driven key command would be:

mc.setDrivenKeyframe ("faceBlends", at= 'Human1', cd= 'ctrlHandle0.tx', dv = 0, v= 0)

Now, I see quite a few other problems that you probably should address before continuing on your script.

1) You relie a lot on direct names and static strings. This will make your script unusable for any scene that doesn't have this exact naming convention. Using dynamic variables is normally the better way to go.

2) You call your UI in the middle of the creation process, this means that you'll create new blendshapes whenever you want to open the UI. I would initialise your UI first and have it probably contain a button that creates the blenshape.

3) In the same line as nr. 2, It lacks structure. At the moment it does 3 things at once (UI that seems to do a lot more later, create blendshapes, create controllers for blendshapes). You should probably split those functionalities into separate functions that can be triggered by the UI, or even consider having multiple scripts.

I hope it helps!

0 Likes