Home Website Youtube GitHub

Variables in mGear's Picker Action Scripts?

Hi all,

I’m attempting to write a script that will let an animator click on a Picker square and select an attribute on the face Control accordingly to MM drag and animate. The issue I’m running into currently is that this script that I’ve made for the face squares works perfectly in the Script Editor of Maya, but NOT in the Action Script section in mGear’s Anim Picker due to it not re-assigning the ‘nameSpace’ variable in the Action Script? Is the Action Script unable to change global variables, or could it be a bug? I haven’t found much documentation about the Action Script for Anim Picker buttons to find out more about how it’s working internally…

    import maya.cmds as cmds
    import maya.mel as mel

    nameSpace = __NAMESPACE__
    # Creates the full name of the Attribute that will be selected
    faceControl = "%s:upperFace_ctrl.InnerBrowRaiser_L_AU1"%nameSpace

     # Selects the full Control
    cmds.select("%s:upperFace_ctrl"%nameSpace)

    # Converts Python variable to Mel variable
    mel.eval('string $faceControlMel = `python "faceControl"`;')

    # Selects the Attribute in the Channel Box making it available for quick animation
    mel.eval('channelBox -edit -select $faceControlMel mainChannelBox;')

Thank you!

hmm, it works fine for me. I notice both in your button and in the script editor, your script must be run twice. The first time selects the control. The 2nd time it selects the attribute. I’m not sure why, but I have no idea about MEL or its scopes.

What version of Maya? What version of mGear?

And silly question, but just double-checking: After setting the script, did you change the button to “Custom action (script)”? If it is set to “Default action”, the script won’t work, or possibly even save.

1 Like

Oh, now I see what you mean. Once it is run in the script editor, it does work. But if you name a new control and run it right from the Picker, it doesn’t. So it is some kind of scope thing.

But here is an alternative. Nevermind about declaring the MEL variable. Just use the faceControl string you already declared. You can concatenate Python strings right into mel.eval().

import maya.cmds as cmds
import maya.mel as mel

nameSpace = __NAMESPACE__
# Creates the full name of the Attribute that will be selected
faceControl = "%s:upperFace_ctrl.InnerBrowRaiser_L_AU1"%nameSpace

 # Selects the full Control
cmds.select("%s:upperFace_ctrl"%nameSpace)

# Selects the Attribute in the Channel Box making it available for quick animation
mel.eval('channelBox -edit -select ' + faceControl + ' mainChannelBox;')

3 Likes

Hi Chris,

Awesome, that’s exactly what I needed! You’re definitely right that running Python within Mel within Python was causing some scope problems, but I hadn’t thought about how mel.eval is still Python and can do Python-y stuff as well like concatenation, that’ll be nice to have in my back pocket in the future! Thank you so much! :grin:

1 Like

I don’t think you have to go through MEL to access the channelBox function

cmds.channelBox('mainChannelBox', edit=1, select=faceControl)
2 Likes