-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathresetAttrs.py
50 lines (35 loc) · 1.35 KB
/
resetAttrs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import apiExtensions
from maya.cmds import *
from filesystem import removeDupes
def resetAttrs( obj, skipVisibility=True ):
'''
simply resets all keyable attributes on a given object to its default value
great for running on a large selection such as all character controls...
'''
#obj = apiExtensions.asMObject( obj )
attrs = listAttr( obj, k=True, s=True, m=True ) or []
if skipVisibility:
if 'visibility' in attrs:
attrs.remove( 'visibility' )
if not attrs:
return
selAttrs = channelBox( 'mainChannelBox', q=True, sma=True ) or channelBox( 'mainChannelBox', q=True, sha=True )
for attr in attrs:
#if there are selected attributes AND the current attribute isn't in the list of selected attributes, skip it...
if selAttrs:
attrShortName = attributeQuery( attr, n=obj, shortName=True )
if attrShortName not in selAttrs:
continue
default = 0
try:
default = attributeQuery( attr, n=obj, listDefault=True )[ 0 ]
except RuntimeError: pass
attrpath = '%s.%s' % (obj, attr)
if not getAttr( attrpath, settable=True ):
continue
#need to catch because maya will let the default value lie outside an attribute's
#valid range (ie maya will let you creat an attrib with a default of 0, min 5, max 10)
try:
setAttr( attrpath, default )
except RuntimeError: pass
#end