Search code examples
pythonjobsmaya

Maya Python Script Job Attribute Change


I am trying to get one boolean attribute (A) to change another(B). The one to be controlled (B) already has a script job running it and so I can't create a set driven key, direct connection, or expression to control it, so I'm trying another script job, since running the script function by itself achieves the desired result. I just can't figure out how to tie that script to run to the attribute change (B) that I want to drive it by (A).

This is placed in a script node set to the open gui trigger (to load when maya opens as I understand it). Here's a screenshot.

What am I missing here?

import maya.cmds as cmds

def togglePicker(pickerAttr):

    cmds.setAttr(pickerAttr, not 0)
    

nameSpace = cmds.ls(sl=True)[0].rpartition(':')[0]

if len(nameSpace) > 0:
    pickerAttr = nameSpace + ':Main.picker'
    myPickerAttr = nameSpace + ':MoverMain_Cntrl.Picker'
else:
    pickerAttr = 'Main.picker'
    myPickerAttr = 'MoverMain_Cntrl.Picker'
    
 
cmds.scriptJob(attributeChange=[myPickerAttr,togglePicker])

Solution

  • I got it to work! (previously I had switched to the script node to MEL so I could test the mel command mentioned in the comments that did work, but I forgot to switch back to python when I realized the selection issue I also mentioned in the comments).

    So here's what worked, where I know I'll have to manually change the namespace name in case the scene file name changes:

    import maya.cmds as cmds
    
    def togglePicker():
        cmds.setAttr(pickerAttr, not 0)
    
    if cmds.namespace(exists='ExtremeBallRig_v008'):
        pickerAttr = 'ExtremeBallRig_v008:Main.picker'
        myPickerAttr = 'ExtremeBallRig_v008:MoverMain_Cntrl.Picker'
    else:
        pickerAttr = 'Main.picker'
        myPickerAttr = 'MoverMain_Cntrl.Picker'
        
    cmds.scriptJob(attributeChange=[myPickerAttr,togglePicker])