()
| 9 | import MaterialX as mx |
| 10 | |
| 11 | def main(): |
| 12 | parser = argparse.ArgumentParser(description="Verify that the given file is a valid MaterialX document.") |
| 13 | parser.add_argument("--resolve", dest="resolve", action="store_true", help="Resolve inheritance and string substitutions.") |
| 14 | parser.add_argument("--verbose", dest="verbose", action="store_true", help="Print summary of elements found in the document.") |
| 15 | parser.add_argument(dest="inputFilename", help="Filename of the input document.") |
| 16 | opts = parser.parse_args() |
| 17 | |
| 18 | # Load standard libraries automatically. |
| 19 | stdlib = mx.createDocument() |
| 20 | try: |
| 21 | mx.loadLibraries(mx.getDefaultDataLibraryFolders(), mx.getDefaultDataSearchPath(), stdlib) |
| 22 | except Exception as err: |
| 23 | print(err) |
| 24 | sys.exit(0) |
| 25 | |
| 26 | # Read and validate the source document. |
| 27 | doc = mx.createDocument() |
| 28 | try: |
| 29 | mx.readFromXmlFile(doc, opts.inputFilename) |
| 30 | doc.setDataLibrary(stdlib) |
| 31 | except mx.ExceptionFileMissing as err: |
| 32 | print(err) |
| 33 | sys.exit(0) |
| 34 | valid, message = doc.validate() |
| 35 | if (valid): |
| 36 | print("%s is a valid MaterialX document in v%s" % (opts.inputFilename, mx.getVersionString())) |
| 37 | else: |
| 38 | print("%s is not a valid MaterialX document in v%s" % (opts.inputFilename, mx.getVersionString())) |
| 39 | print(message) |
| 40 | |
| 41 | # Generate verbose output if requested. |
| 42 | if opts.verbose: |
| 43 | nodegraphs = doc.getNodeGraphs() |
| 44 | materials = doc.getMaterialNodes() |
| 45 | looks = doc.getLooks() |
| 46 | lookgroups = doc.getLookGroups() |
| 47 | collections = doc.getCollections() |
| 48 | nodedefs = doc.getNodeDefs() |
| 49 | implementations = doc.getImplementations() |
| 50 | geominfos = doc.getGeomInfos() |
| 51 | geompropdefs = doc.getGeomPropDefs() |
| 52 | typedefs = doc.getTypeDefs() |
| 53 | propsets = doc.getPropertySets() |
| 54 | variantsets = doc.getVariantSets() |
| 55 | backdrops = doc.getBackdrops() |
| 56 | |
| 57 | print("----------------------------------") |
| 58 | print("Document Version: {}.{:02d}".format(*doc.getVersionIntegers())) |
| 59 | print("%4d Custom Type%s%s" % (len(typedefs), pl(typedefs), listContents(typedefs, opts.resolve))) |
| 60 | print("%4d Custom GeomProp%s%s" % (len(geompropdefs), pl(geompropdefs), listContents(geompropdefs, opts.resolve))) |
| 61 | print("%4d NodeDef%s%s" % (len(nodedefs), pl(nodedefs), listContents(nodedefs, opts.resolve))) |
| 62 | print("%4d Implementation%s%s" % (len(implementations), pl(implementations), listContents(implementations, opts.resolve))) |
| 63 | print("%4d Nodegraph%s%s" % (len(nodegraphs), pl(nodegraphs), listContents(nodegraphs, opts.resolve))) |
| 64 | print("%4d VariantSet%s%s" % (len(variantsets), pl(variantsets), listContents(variantsets, opts.resolve))) |
| 65 | print("%4d Material%s%s" % (len(materials), pl(materials), listContents(materials, opts.resolve))) |
| 66 | print("%4d Collection%s%s" % (len(collections), pl(collections), listContents(collections, opts.resolve))) |
| 67 | print("%4d GeomInfo%s%s" % (len(geominfos), pl(geominfos), listContents(geominfos, opts.resolve))) |
| 68 | print("%4d PropertySet%s%s" % (len(propsets), pl(propsets), listContents(propsets, opts.resolve))) |
no test coverage detected