PDA

View Full Version : Select custom attr via GUI?


EightBit
11-01-2010, 02:33 PM
I am working on a rigging tool to update SDK controllers.
Basically, it parses all the SDK connections to an object, and facilitates updating the SDK after repositioning the driven objects.
The application is for a skeletal facial system.
I have it working if the controller is a typical node which can be moved (ie from 1 to -1 in Y). It is easy to load the controller into the tool by selecting it and grabbing the selection.
However, I would also like to get it working for custom attributes, but how to grab them via a UI?
For example, say I have an empty group with an "open_close" slider as a custom attr - what tool could I build to allow the user to select that attr as the current attr?
If I could get the custom attr to be listed in the channel box, perhaps it could be selected (channels in the CB are selectable), but that doesn't happen automatically when the attr is added to the node.
Any suggestions?
Thanks.

NaughtyNathan
11-01-2010, 04:48 PM
you can see attributes in the outliner (if you turn on "Display > Attributes (channels)") which would allow users to select them easily. You could also create a very simple "picker" UI from a window with a form-attached textScrollList, that displayed a list of all custom attributes on the selected node (which you can query by: `listAttr -ud $node`). As soon as the user clicked an entry on the textScrollList you could fire off your process..?

Attributes aren't visible in the Channel Box unless they are keyable, so you could also make the custom attributes keyable and they'd show up in the channel box, but I'm not sure if that would actually work for all attr types..?

:nathaN

EightBit
11-02-2010, 04:59 PM
Thanks a lot Nathan:
The outliner is too messy, but I like your UI idea.
I've got it mostly working but when I grab the UD Attr from the textScrollList, I get unicode and I'm having trouble converting it to a proper string - any suggestions (see the errors in the 'selectAttr' def).
winName = "tmp"
if cmds.window(winName,exists=1):
cmds.deleteUI(winName)
testing = False
#Delete windowPrefs when testing, might generate error if existence is not tested for also:
if (testing and windowPref(winName, exists=True)):
cmds.windowPref( winName, remove=True )
cmds.window(winName,wh=(220, 180),resizeToFitChildren=True,title="test UD Attr Picker")
cmds.formLayout('attrForm')
cmds.text('UDAttrText',l="User Defined Attrs in Selected :")
cmds.textScrollList('UDAttrsList',h=110)

cmds.button('getAttrsBtn',l="Get Attrs",c=lambda *args: listUDAttrs())

# EDIT formLayout
cmds.formLayout('attrForm',e=1,ap=[('UDAttrText', 'left', 0, 4), ('UDAttrsList', 'left', 0, 4), ('getAttrsBtn', 'left', 0, 4)],
ac = [ ('UDAttrsList', 'top',3, 'UDAttrText'), ('getAttrsBtn', 'top',3, 'UDAttrsList') ] )
cmds.showWindow()

def listUDAttrs():
cmds.textScrollList('UDAttrsList',e=1,ra=1) # Remove All
currObj = cmds.ls (sl=1)
UDAttrs = cmds.listAttr (currObj, ud = 1)
for currAttr in UDAttrs:
cmds.textScrollList('UDAttrsList',e=1,a=currAttr, selectCommand=lambda *args: selectAttr(currObj))

def selectAttr(currObj):
attrName = cmds.textScrollList('UDAttrsList',q=1,si=1)# Error: TypeError: coercing to Unicode: need string or buffer, list found #
#attrName = str ( cmds.textScrollList('UDAttrsList',q=1,si=1) ) # Error: TypeError: Object internalA.[u'pCube5'] is invalid #
cmds.select (currObj[0]+'.'+attrName )
selected = cmds.ls (sl=1)
print 'attr Selected',selected

NaughtyNathan
11-02-2010, 05:15 PM
I don't think unicode is a problem, querying the selected items of a textScrollList always returns a list, even with only one item selected. This is the issue I think. add [0] to the end:

attrName = cmds.textScrollList('UDAttrsList',q=1,si=1)[0] # always returns a list, so grab index [0]
:nathaN

EightBit
11-02-2010, 05:16 PM
That did it!
Thanks a lot for the quick reply mate!
...back to work

CGTalk Moderation
11-02-2010, 05:16 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.