-
Notifications
You must be signed in to change notification settings - Fork 36
/
generate_cmdt.py
79 lines (65 loc) · 1.93 KB
/
generate_cmdt.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Generate cmdt.py, with all available Type IDs"""
import os
import sys
from maya.api import OpenMaya as om
from maya import standalone, cmds
def main(fname=None):
standalone.initialize()
blacklist = (
# Causes crash (Maya 2018)
"caddyManipBase",
# Causes TypeError
"applyAbsOverride",
"applyOverride",
"applyRelOverride",
"childNode",
"lightItemBase",
"listItem",
"override",
"selector",
"valueOverride",
)
cmdt = [
"from maya.api import OpenMaya as om",
""
]
dg = om.MFnDependencyNode()
for name in cmds.allNodeTypes():
if name in blacklist:
continue
try:
mobj = dg.create(name)
print(mobj.apiType())
fn = om.MFnDependencyNode
try:
# If `name` is a shape, then the transform
# is returned. We need the shape.
mobj = om.MFnDagNode(mobj).child(0)
except RuntimeError:
pass
except TypeError:
# This shouldn't happen, but might depending
# on the Maya version, and if there are any
# custom plug-ins registereing new (bad) nodes.
#
# If so:
# Add to `blacklist`
#
sys.stderr.write("%s threw a TypeError\n" % name)
continue
typeId = fn(mobj).typeId
cmdt += ["{type} = om.MTypeId({id})".format(
type=name[0].upper() + name[1:],
id=str(typeId))
]
text = os.linesep.join(cmdt)
dirname = os.path.dirname(__file__)
fname = fname or os.path.join(dirname, "cmdt.py")
with open(fname, "w") as f:
f.write(text)
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--fname", default="")
opt = parser.parse_args()
main(opt.fname)