Jump to content
  • 0
Jarom Brand

Maya get Attributes in channelbox

Question

Does anyone know how to get a list of all the attributes that show up in the channelBox? I have something that works for transforms, but if I try it on shapes I get way more than I want. 

 

This is what I have so far:

import pymel.core as pm

def getChannelBoxAttrs(obj):
    '''
    Returns a list of all the visible attributes

    @param PyNode:          object              The ojects whoes attributes will be toggled
    @return list:           Returns a list of the attributes in the channelBox
    '''
    visible_attrs = []
    attribs = obj.listAttr(k=True, u=True)
    attribs.extend(obj.listAttr(k=True, l=True))
    attribs.extend(obj.listAttr(cb=True))

    #remove the parent transform attributes from the list
    parent_attrs = ['translate', 'rotate', 'scale']

    for attrib in attribs:
        if not attrib.attrName(longName=True) in parent_attrs:
            visible_attrs.append(attrib)
    return visible_attrs

obj = pm.selected()[0]
getChannelBoxAttrs(obj)

 

If I have a  shape selected when I run this I will get this as a return:

# Result: [Attribute(u'nurbsCircleShape1.controlPoints[-1].xValue'),
 Attribute(u'nurbsCircleShape1.controlPoints[-1].yValue'),
 Attribute(u'nurbsCircleShape1.controlPoints[-1].zValue'),
 Attribute(u'nurbsCircleShape1.uvSet[-1].uvSetName'),
 Attribute(u'nurbsCircleShape1.colorSet[-1].colorName'),
 Attribute(u'nurbsCircleShape1.colorSet[-1].clamped'),
 Attribute(u'nurbsCircleShape1.colorSet[-1].representation'),
 Attribute(u'nurbsCircleShape1.aiUserOptions'),
 Attribute(u'nurbsCircleShape1.aiTraceSets'),
 Attribute(u'nurbsCircleShape1.aiSssSetname'),
 Attribute(u'nurbsCircleShape1.aiRenderCurve'),
 Attribute(u'nurbsCircleShape1.aiCurveWidth'),
 Attribute(u'nurbsCircleShape1.aiSampleRate'),
 Attribute(u'nurbsCircleShape1.aiCurveShader'),
 Attribute(u'nurbsCircleShape1.aiCurveShaderR'),
 Attribute(u'nurbsCircleShape1.aiCurveShaderG'),
 Attribute(u'nurbsCircleShape1.aiCurveShaderB')] #

Even though most of those don't actually show up in the channelBox. 

Also If anyone has a more elegant way of stripping out parent attributes, I'd love to see it. I never like hard coding things like that. 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi @jarom,

Are you interested in just getting user defined attributes that are in the channel box?

In that case you could use:

obj.listAttr(k=True, ud=True)

where ud is for UserDefined - only new attributes that aren't part of the base object.

Share this post


Link to post
Share on other sites
  • 0

Hey Jason,

What I would really like is to get both dynamic and non-dynamic attributes that show up in the channelbox. I guess I could check to see if the object is a shape or a transform, and if it's a shape, only look for the user defined attributes which would probably work 99.9% of the time since I always lock and hide all non-dynamic attributes on shapes when dealing with them. But the perfectionist in me really wants it to work as described:)

 

Thanks for the suggestion. I thought using the cb flag would do the same, but its leaving a bunch of them out. Not sure what that flag is actually doing. Ill have to dig into the mel scripts to find out. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Similar Content

    • By Jason
      I was getting a TON of crashes in Maya yesterday... like nearly every 5 minutes!
      The rig i'm using is super simple, basically just a bunch of constraints. So I set my evaluation mode to serial instead of parallel, and got zero crashes.
      I know this isn't a long-term solution.. but for now, at least I can work.
      To do this, go to:
      Windows -> Settings / Preferences -> Preferences
      Click on  Animation
      Set evaluation mode to Serial.

    • By Jason
      I was thinking about rigging systems and was wondering if anyone had any experience with mgear or other systems in Maya?  @Brad Clark you said you got mgear working in Nimble - can you tell us about it?
    • By Jarom Brand
      Ever since Autodesk included Arnold in maya, every NURBS curveShape now has these attributes:
      aiRenderCurve aiCurveWidth aiSampleRate aiCurveShaderR aiCurveShaderG aiCurveShaderB
       
      I like to place instanced NURBS curveShapes under controls to give animators access to the same attributes across multiple controls, say a fk/ik switch. So, to clean things up, I will lock and hide those new attributes and add my own:

      For the most part this works great, but those attributes that I locked and hid will randomly pop back into the Channel Box on their own. 

       
      I assume it has something to do with Arnold plugin and that its putting them back, but I'd like to stop that from happening. Any Ideas? 
       
       
×
×
  • Create New...