12 Command to convert from JSON to XML representation of a MaterialX document
14 parser = argparse.ArgumentParser(description=
"Utility to convert from JSON to XML representation of a MaterialX document")
15 parser.add_argument(
'--outputPath', dest=
'outputPath', default=
'', help=
'File path to output results to.')
16 parser.add_argument(
'--upgradeVersion', dest=
'upgradeVersion', type=mx.stringToBoolean, default=
True, help=
'Upgrade document version. Default is True.')
17 parser.add_argument(dest=
"inputFileName", help=
"Filename of the input document or folder containing input documents")
19 opts = parser.parse_args()
23 opts.outputPath = os.path.abspath(opts.outputPath)
24 outputPath = mx.FilePath(opts.outputPath)
26 if outputPath.size() > 0:
27 if os.path.isdir(outputPath.asString()):
28 print(
'Output path "%s" does not exist.' % outputPath.asString())
31 print(
'- Write files to outputPath: '+ opts.outputPath)
35 if os.path.isdir(opts.inputFileName):
36 fileList = core.Util.getFiles(opts.inputFileName, extension)
38 extension = mx.FilePath(opts.inputFileName).getExtension()
39 if extension ==
'json':
40 fileList.append(opts.inputFileName)
43 print(
'No files found with extension "%s"' % extension)
49 for fileName
in fileList:
51 if extension ==
'json':
52 if mx.FilePath(fileName).isAbsolute():
53 outputFilePath = mx.FilePath(fileName.replace(
'.json',
'_json.mtlx'))
55 outputFilePath = outputPath / mx.FilePath(fileName.replace(
'.json',
'_json.mtlx'))
56 outputFileName = outputFilePath.asString()
58 readOptions.upgradeVersion = opts.upgradeVersion
59 converted = core.Util.jsonFileToXmlFile(fileName, outputFileName, readOptions)
60 print(
'Convert JSON file "%s" -> XML file "%s". Status: %s' % (fileName, outputFileName, converted))