Sticky Lips code returning "invalid syntax"

Sticky Lips code returning "invalid syntax"

Anonymous
Not applicable
1,257 Views
4 Replies
Message 1 of 5

Sticky Lips code returning "invalid syntax"

Anonymous
Not applicable

I'm currently trying to rig a stick-lips feature to my character, but when I run the python to create the set ranges, all I get is an "invalid syntax" error. This is not very useful in trying to figure out the problem...do any more experienced pymel users have an idea of what's going on?

 

Below is my code:

import pymel.core as pm

lf_main_attr = "cc_jaw.L_Sticky_Lips"
rt_main_attr = "cc_jaw.R_Sticky_Lips"
lip_val_list = [30, 30]
lip_name_list = ['upperLip', 'lowerLip']

name_counter = 0
for each in lip_val_list:
    half_val = (each / 2) + 1
    total_val = each + 1
    div_val = 10.0 / half_val
    counter = 0
    while(counter<half_val):
        lip_sr = pm.shadingNode( 'setRange', asUtility=True, n='lf_' + lip_name_list[name_counter] + str(counter+1) + '_setRange')
        pm.setAttr(lip_sr + '.oldMaxX', (div_val * (counter+1)))
        pm.setAttr(lip_sr + '.oldMinX', (div_val * counter))
        pm.setAttr(lip_sr + '.maxX', 0)
        pm.setAttr(lip_sr + '.minX', 1)
        if counter == (half_val - 1):
            pm.setAttr(lip_sr + '.minX', 0.5)
        pm.connectAttr(lf_main_attr, lip_sr + '.valueX', f=True)
        
        lip_flip_sr = pm.shadingNode( 'setRange', asUtility=True, n='lf_' + lip_name_list[name_counter] + '_flip' + str(counter+1) + '_setRange')
        pm.setAttr(lip_flip_sr + '.oldMaxX', 1)
        if counter == (half_val - 1):
            pm.setAttr(lip_flip_sr + '.oldMaxX', 0.5)
        pm.setAttr(lip_flip_sr + '.oldMinX', 0)
        pm.setAttr(lip_flip_sr + '.maxX', 0)
        pm.setAttr(lip_flip_sr + '.minX', 1)
        if counter == (half_val - 1):
            pm.setAttr(lip_flip_sr + '.minX', 0.5)
        pm.connectAttr(lip_sr + '.outValueX', lip_flip_sr + '.valueX', f=True)
            
        if counter == (half_val - 1):
            mid_pma = pm.shadingNode( 'plusMinusAverage', asUtility=True, n='ct_' + lip_name_list[name_counter] + str(counter+1) + '_plusMinusAverage')
            pm.connectAttr(lip_sr + '.outValueX', mid_pma + '.input2D[0].input2Dx', f=True)
            pm.connectAttr(lip_flip_sr + '.outValueX', mid_pma + '.input2D[0].input2Dy', f=True)
        else:
            pm.connectAttr(lip_sr + '.outValueX', lip_name_list[name_counter] + '_wire_bShape.inputTarget[0].inputTargetGroup[0].targetWeights[' + str(counter) + ']', f=True)
            pm.connectAttr(lip_flip_sr + '.outValueX', lip_name_list[name_counter] + '_wire_bShape.inputTarget[0].inputTargetGroup[1].targetWeights[' + str(counter) + ']', f=True)
        
        counter = counter + 1
        
    #div_val = 10.0 / 39
    counter = half_val - 1
    rev_counter = half_val
    while(counter<total_val):
        lip_sr = pm.shadingNode( 'setRange', asUtility=True, n='rt_' + lip_name_list[name_counter] + str(counter+1) + '_setRange')
        pm.setAttr(lip_sr + '.oldMaxX', (div_val * rev_counter))
        pm.setAttr(lip_sr + '.oldMinX', (div_val * (rev_counter-1)))
        pm.setAttr(lip_sr + '.maxX', 0)
        pm.setAttr(lip_sr + '.minX', 1)
        if counter == (half_val - 1):
            pm.setAttr(lip_sr + '.minX', 0.5)
        pm.connectAttr(rt_main_attr, lip_sr + '.valueX', f=True)
        
        lip_flip_sr = pm.shadingNode( 'setRange', asUtility=True, n='rt_' + lip_name_list[name_counter] + '_flip' + str(counter+1) + '_setRange')
        pm.setAttr(lip_flip_sr + '.oldMaxX', 1)
        if counter == (half_val - 1):
            pm.setAttr(lip_flip_sr + '.oldMaxX', 0.5)
        pm.setAttr(lip_flip_sr + '.oldMinX', 0)
        pm.setAttr(lip_flip_sr + '.maxX', 0)
        pm.setAttr(lip_flip_sr + '.minX', 1)
        if counter == (half_val - 1):
            pm.setAttr(lip_flip_sr + '.minX', 0.5)
        pm.connectAttr(lip_sr + '.outValueX', lip_flip_sr + '.valueX', f=True)
        
        if counter == (half_val - 1):
            pm.connectAttr(lip_sr + '.outValueX', mid_pma + '.input2D[1].input2Dx', f=True)
            pm.connectAttr(lip_flip_sr + '.outValueX', mid_pma + '.input2D[1].input2Dy', f=True)
            pm.connectAttr(mid_pma + '.output2Dx', lip_name_list[name_counter] + '_wire_bShape.inputTarget[0].inputTargetGroup[0].targetWeights[' + str(counter) + ']', f=True)
            pm.connectAttr(mid_pma + '.output2Dy', lip_name_list[name_counter] + '_wire_bShape.inputTarget[0].inputTargetGroup[1].targetWeights[' + str(counter) + ']', f=True)
        else:
            pm.connectAttr(lip_sr + '.outValueX', lip_name_list[name_counter] + '_wire_bShape.inputTarget[0].inputTargetGroup[0].targetWeights[' + str(counter) + ']', f=True)
            pm.connectAttr(lip_flip_sr + '.outValueX', lip_name_list[name_counter] + '_wire_bShape.inputTarget[0].inputTargetGroup[1].targetWeights[' + str(counter) + ']', f=True)
        
        counter = counter + 1
        rev_counter = rev_counter - 1
    name_counter = name_counter + 1

Thanks in advance!

0 Likes
Accepted solutions (1)
1,258 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Any chance you've got mixed tabs and spaces?


0 Likes
Message 3 of 5

Anonymous
Not applicable

Sorry, could you further explain what you mean by mixed tabs and spaces?

Thanks!

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

Sorry about that, let me clarify. In Python, people typically use four space characters to indent a line, but you can also use a tab character. Which one you're using is determined by your text editor and its settings. If you copy and paste other people's code, you can end up mixing the two indentation conventions. Usually, Python doesn't like it when you mix tabs and spaces for indentation. You can use either one, but it expects you to be consistent. I have sometimes gotten undescriptive errors errors due to this.

 

I copy/pasted your code into my Maya 2018.4 script editor, and it ran ok if I commented out the connectAttr() calls (I don't have your scene, so of course the connectAttr() calls won't work.). This made me wonder if the indentation changed when you copy/pasted the code into the forum post.

0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

I don't know why exactly but it's the very last "1" not being recognized in Maya. I just needed to delete it and type "1" again, then the script ran fine. Thank you for your help!