code, pre {
font-family: Consolas, “Liberation Mono”, Menlo, “Courier Prime Web”, Courier, monospace;
background: #f3f3f3;
}
code {
padding: 1px;
margin: 0 -1px;
border-radius: 3px;
}
pre {
display: block;
line-height: 20px;
text-shadow: 0 1px white;
padding: 5px 5px 5px 30px;
white-space: nowrap;
position: relative;
margin: 1em 0;
}
pre:before {
content: “”;
position: absolute;
top: 0;
bottom: 0;
left: 15px;
border-left: solid 1px #dadada;
}
Render setup is very useful for managing render layers and it can import and export render layers for later usage. However, the information on how to import/export it in Python is quite sparse. After doing some research on our testing code, I found that it is quite easy.
There is renderSetup.decode and renderSetup.encode for import and export, respectively.
The prototype for decode is decode(jsonObject, importOption, optionalPrefix), where
– the jsonObject is the json string you’ll need to import;
– the importOption could be one of the DECODE_AND_RENAME, DECODE_AND_MERGE, DECODE_AND_OVERWRITE value which you could find in the import dialogue;
– the optionalPrefix is the prepend string and it could be None (if you don’t want a prefix) and it is only working with DECODE_AND_RENAME option.
The export command is easier, as it has only one parameter called Note. This valie can be “None” if you do not want to provide a Note.
import maya.app.renderSetup.model.renderSetup as renderSetupimport jsondef importRenderSetup(filename): with open(filename, "r") as file: renderSetup.instance().decode(json.load(file), renderSetup.DECODE_AND_OVERWRITE, None) def exportRenderSetup(filename, note = None): with open(filename, "w+") as file: json.dump(renderSetup.instance().encode(note), fp=file, indent=2, sort_keys=True)
You can use above code snippet to import/export your render setup in Maya.

Leave a Reply