forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mxdoc.py
45 lines (38 loc) · 1.56 KB
/
mxdoc.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
#!/usr/bin/env python
'''
Print markdown documentation for each nodedef in the given document.
'''
import sys, os, argparse
import MaterialX as mx
HEADERS = ('Name', 'Type', 'Default Value',
'Uniform', 'UI min', 'UI max', 'UI Soft Min', 'UI Soft Max', 'UI step', 'UI group', 'UI Advanced')
ATTR_NAMES = ('uniform', 'uimin', 'uimax', 'uisoftmin', 'uisoftmax', 'uistep', 'uifolder', 'uiadvanced')
def main():
parser = argparse.ArgumentParser(description="Print markdown documentation for each nodedef in the given document.")
parser.add_argument(dest="inputFilename", help="Filename of the input MaterialX document.")
opts = parser.parse_args()
doc = mx.createDocument()
try:
mx.readFromXmlFile(doc, opts.inputFilename)
except mx.ExceptionFileMissing as err:
print(err)
sys.exit(0)
for nd in doc.getNodeDefs():
print('- *Nodedef*: %s' % nd.getName())
print('- *Type*: %s' % nd.getType())
print('- *Doc*: %s\n' % nd.getAttribute('doc'))
print('| ' + ' | '.join(HEADERS) + ' |')
print('|' + ' ---- |' * len(HEADERS) + '')
for inp in nd.getInputs():
infos = []
infos.append(inp.getName())
infos.append(inp.getType())
val = inp.getValue()
if inp.getType() == "float":
val = round(val, 6)
infos.append(str(val))
for attrname in ATTR_NAMES:
infos.append(inp.getAttribute(attrname))
print('| ' + " | ".join(infos) + ' |')
if __name__ == '__main__':
main()