talk.bindpose.com has been shut down on the 6th of March 2021. You can read a bit more about it here.

You are currently reading an archived copy of the latest content, with all the usernames deleted.

scriptJob execution when playback stops

by user101 posted 02-08-2018 | 1 comment

Hi, i basically setup a scriptJob with attributeChange on enum for matching IK/FK for left arm. It works fine at the viewport but it's not behaving as i'd expect to when i try to animate it. I'm probably missing something but couldn't find what it is. Here is the video of what's happening:

https://gfycat.com/WellwornEvergreenAdder

The code example just for the left arm:

myCode = '''from maya import cmds, OpenMaya
def leftArmMatch(*arg):

            #IK TO FK
            if cmds.getAttr('arm_L_settings_CTRL.IK') == 10 :
                cmds.matchTransform('arm_L_Shoulder_FK_CTRL', 'arm_L_Shoulder_bind_JNT')
                cmds.matchTransform('arm_L_Elbow_FK_CTRL', 'arm_L_Elbow_bind_JNT')
                cmds.matchTransform('arm_L_Wrist_FK_CTRL', 'arm_L_Wrist_bind_JNT')

                cmds.setAttr('arm_L_settings_CTRL.IK', 0)
            #FK TO IK
            else:
                startJnt = 'arm_L_Shoulder_bind_JNT'
                midJnt = 'arm_L_Elbow_bind_JNT'
                endJnt = 'arm_L_Wrist_bind_JNT'

                start = cmds.xform(startJnt ,q= 1 ,ws = 1,t =1 )
                mid = cmds.xform(midJnt ,q= 1 ,ws = 1,t =1 )
                end = cmds.xform(endJnt ,q= 1 ,ws = 1,t =1 )

                startV = OpenMaya.MVector(start[0] ,start[1],start[2])
                midV = OpenMaya.MVector(mid[0] ,mid[1],mid[2])
                endV = OpenMaya.MVector(end[0] ,end[1],end[2])

                startEnd = endV - startV
                startMid = midV - startV

                dotP = startMid * startEnd
                proj = float(dotP) / float(startEnd.length())
                startEndN = startEnd.normal()
                projV = startEndN * proj

                arrowV = startMid - projV
                arrowV*= 1
                finalV = arrowV + midV

                pv = 'arm_L_Elbow_PV_CTRL'
                cmds.xform(pv , ws =1 , t= (finalV.x , finalV.y ,finalV.z))


                cmds.matchTransform('arm_L_Wrist_IK_CTRL', 'arm_L_Wrist_bind_JNT')

                cmds.setAttr('arm_L_settings_CTRL.IK', 10)

cmds.scriptJob(attributeChange=['arm_L_settings_CTRL.match', leftArmMatch])

#scriptNode

cmds.scriptNode(st=2, bs=myCode.replace("'''", "''"), n='matchScriptNode', stp='python')

 

by user215 posted 04-08-2018

Try switching from Parallel evaluation mode to DG or even Serial.

Sometimes, Maya's viewport 2.0 with parallel processing tries to optimize performance in funky ways, leading to stuff not being evaluated properly.

Alternatively, look into callbacks in openmaya. It's a better alternative to scriptjobs.