Uh oh!
There was an error while loading. Please reload this page.
forked from AcademySoftwareFoundation/MaterialX
- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmxdoc.py
More file actions
Latest commit
113 lines (104 loc) · 5.07 KB
/
Copy pathmxdoc.py
File metadata and controls
113 lines (104 loc) · 5.07 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python
'''
Print markdown documentation for each nodedef in the given document.
'''
importargparse
importsys
importMaterialXasmx
HEADERS= ('Name', 'Type', 'Default Value',
'UI name', 'UI min', 'UI max', 'UI Soft Min', 'UI Soft Max', 'UI step', 'UI group', 'UI Advanced', 'Doc', 'Uniform')
ATTR_NAMES= ('uiname', 'uimin', 'uimax', 'uisoftmin', 'uisoftmax', 'uistep', 'uifolder', 'uiadvanced', 'doc', 'uniform' )
defmain():
parser=argparse.ArgumentParser(description="Print documentation for each nodedef in the given document.")
parser.add_argument(dest="inputFilename", help="Filename of the input MaterialX document.")
parser.add_argument('--docType', dest='documentType', default='md', help='Document type. Default is "md" (Markdown). Specify "html" for HTML output')
parser.add_argument('--showInherited', default=False, action='store_true', help='Show inherited inputs. Default is False')
opts=parser.parse_args()
doc=mx.createDocument()
try:
mx.readFromXmlFile(doc, opts.inputFilename)
exceptmx.ExceptionFileMissingaserr:
print(err)
sys.exit(0)
forndindoc.getNodeDefs():
# HTML output
ifopts.documentType=="html":
print('<head><style>')
print('table, th, td {')
print(' border-bottom: 1px solid; border-collapse: collapse; padding: 10px;')
print('}')
print('</style></head>')
print('<ul>')
print('<li> <em>Nodedef</em>: %s'%nd.getName())
print('<li> <em>Type</em>: %s'%nd.getType())
iflen(nd.getNodeGroup()) >0:
print('<li> <em>Node Group</em>: %s'%nd.getNodeGroup())
iflen(nd.getVersionString()) >0:
print('<li> <em>Version</em>: %s. Is default: %s'% (nd.getVersionString(), nd.getDefaultVersion()))
iflen(nd.getInheritString()) >0:
print('<li> <em>Inherits From</em>: %s'%nd.getInheritString())
print('<li> <em>Doc</em>: %s\n'%nd.getAttribute('doc'))
print('</ul>')
print('<table><tr>')
forhinHEADERS:
print('<th>'+h+'</th>')
print('</tr>')
inputList=nd.getActiveInputs() ifopts.showInheritedelsend.getInputs()
tokenList=nd.getActiveTokens() ifopts.showInheritedelsend.getTokens()
outputList=nd.getActiveOutputs() ifopts.showInheritedelsend.getOutputs()
totalList=inputList+tokenList+outputList;
forportintotalList:
print('<tr>')
infos= []
ifportinoutputList:
infos.append('<em>'+port.getName() +'</em>')
elifportintokenList:
infos.append(port.getName())
else:
infos.append('<b>'+port.getName() +'</b>')
infos.append(port.getType())
val=port.getValue()
ifport.getType() =="float":
val=round(val, 6)
infos.append(str(val))
forattrnameinATTR_NAMES:
infos.append(port.getAttribute(attrname))
forinfoininfos:
print('<td>'+info+'</td>')
print('</tr>')
print('</table>')
# Markdown output
else:
print('- *Nodedef*: %s'%nd.getName())
print('- *Type*: %s'%nd.getType())
iflen(nd.getNodeGroup()) >0:
print('- *Node Group*: %s'%nd.getNodeGroup())
iflen(nd.getVersionString()) >0:
print('- *Version*: %s. Is default: %s'% (nd.getVersionString(), nd.getDefaultVersion()))
iflen(nd.getInheritString()) >0:
print('- *Inherits From*: %s'%nd.getInheritString())
print('- *Doc*: %s\n'%nd.getAttribute('doc'))
print('| '+' | '.join(HEADERS) +' |')
print('|'+' ---- |'*len(HEADERS) +'')
inputList=nd.getActiveInputs() ifopts.showInheritedelsend.getInputs()
tokenList=nd.getActiveTokens() ifopts.showInheritedelsend.getTokens()
outputList=nd.getActiveOutputs() ifopts.showInheritedelsend.getOutputs()
totalList=inputList+tokenList+outputList;
forportintotalList:
infos= []
ifportinoutputList:
infos.append('*'+port.getName() +'*')
elifportintokenList:
infos.append(port.getName())
else:
infos.append('**'+port.getName() +'**')
infos.append(port.getType())
val=port.getValue()
ifport.getType() =="float":
val=round(val, 6)
infos.append(str(val))
forattrnameinATTR_NAMES:
infos.append(port.getAttribute(attrname))
print('| '+" | ".join(infos) +' |')
if__name__=='__main__':
main()