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 renderSetup
import json
def 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.
Comments
You can follow this conversation by subscribing to the comment feed for this post.