hiding Attributes in the CB with an expression

756 views
Skip to first unread message

Berg Jones

unread,
Nov 25, 2012, 9:27:43 PM11/25/12
to python_in...@googlegroups.com
I have one control that I'm using to control FK/IK on a leg. I dont want to have one for IK and one for FK because it gets confusing. Right now I have reverse foot roll and translate attributes that I want to hide when I'm in FK mode and vice versa.

Heres the expression in question that will  disable translateX but wont unhide switch into IK.

Thanks!!!!

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

mel.eval('proc hideStuff(){setAttr -k 0 "legCtrl1.tx";}')
mel.eval('proc showStuff(){setAttr -k 1 "legCtrl1.tx";}')

myExpr = '''
if (legCtrl1.fkik == 0)
{
    hideStuff();
}

else if (legCtrl1.fkik == 1)
{
    showStuff();
}
'''

cmds.expression(string=myExpr)

Stephen

unread,
Nov 26, 2012, 4:19:08 AM11/26/12
to python_in...@googlegroups.com, python_in...@googlegroups.com
I'm not in front of maya right now. But I'm pretty sure you need to use visible flag in your script.  

Channels can be keyable and not visible as well as visible and not keyable.  

The flag is either -v or -cb or something like that. 

Hth. 

-=s 




Berg Jones

unread,
Nov 26, 2012, 11:16:33 AM11/26/12
to python_in...@googlegroups.com
No, thats not how it works. The code I have is correct.

Justin Israel

unread,
Nov 26, 2012, 11:59:58 AM11/26/12
to python_in...@googlegroups.com
What is the actual question here? I am not clear on it.

Justin Israel

unread,
Nov 26, 2012, 12:11:00 PM11/26/12
to python_in...@googlegroups.com
I feel like an expression may not be the best spot for this functionality. Wouldn't that imply that it would only get evaluated when the time changes or the node is dirty? It seems to me what you want is a trigger that reacts to actually changing your "fkik" setting.

A script job probably suits the situation better:

##
def toggleStuff():
    val = cmds.getAttr('legCtrl1.fkik')
    if val == 0:
        cmds.setAttr('legCtrl1.tx', k=False)
    elif val == 1:
        cmds.setAttr('legCtrl1.tx', k=True)
        
jobId = cmds.scriptJob(attributeChange=['legCtrl1.fkik', toggleStuff])
##

This will immediately react to the change of your fkik attribute, and run a python function that can check and change your attributes.

-- justin



Josh Carey

unread,
Nov 26, 2012, 12:16:32 PM11/26/12
to python_in...@googlegroups.com

You probably don't want to toggle the keyable status... What if the animator has keys on that attr?  I don't know off the top of my head if Maya would keep those keys or not.

Justin Israel

unread,
Nov 26, 2012, 12:24:03 PM11/26/12
to python_in...@googlegroups.com
It would still keep the animation channel. Just makes it no longer addressable for keying in the channel box. I can still key it in the curve editor even with it not keyable.

Berg Jones

unread,
Nov 26, 2012, 2:31:41 PM11/26/12
to python_in...@googlegroups.com
Thanks Justin!

Владимир Пылев

unread,
Nov 26, 2012, 12:47:58 AM11/26/12
to python_in...@googlegroups.com
I could not quite understand, but we can about how to use scriptJob? scriptJob on legCtrl1.fkik  -> myExpr - make the procedure, which contains the show or hide depending on conditions.sorry if that translate translator.

2012/11/26 Berg Jones <berg...@gmail.com>

--

Justin Israel

unread,
Nov 28, 2012, 7:46:59 PM11/28/12
to python_in...@googlegroups.com
Sorry, I am not sure if I understood your question properly. There would be no expression involved in my suggestion. 
legCtrl1.fkik would simply be a boolean 0 or 1 type.
You create the scriptJob completely outside of that property. The scriptJob simply says "run this code when this attribute changes values".

Now you don't have to pass it a callable object. You could have passed it python strings:

###
jobId = cmds.scriptJob(attributeChange=['legCtrl1.fkik', """
val = cmds.getAttr('legCtrl1.fkik')
if val == 0:
    cmds.setAttr('legCtrl1.tx', k=False)
elif val == 1:
    cmds.setAttr('legCtrl1.tx', k=True)
"""])
###

Because you are working with the python commands module, the commands expect python code, not MEL procs.

-- justin



The documentation for scriptJob is here:

You would not be using expressions (from my example). You would be passing callable functions.
Reply all
Reply to author
Forward
0 new messages