How to assign a dictionary of key/value render settings from json to Maya's render settings

How to assign a dictionary of key/value render settings from json to Maya's render settings

craig_kane
Participant Participant
696 Views
2 Replies
Message 1 of 3

How to assign a dictionary of key/value render settings from json to Maya's render settings

craig_kane
Participant
Participant

Hi

I want to apply a dictionary of key/value data from a json file into Maya's render settings.

 

Currently, I have a dictionary of 16 items formatted as follows:

 

{u'defaultRenderGlobals.blurSharpness': 1.0, u'defaultRenderGlobals.enableDefaultLight': False}


I am unsure how exactly I should loop through the data and assign it all to the correct attributes inside Mata using cmds.setAttr() command. 

 

Could anyone suggest a good method to assign them all? I am aware that Maya recommends it's own function to load the full render setup json, but here I am looking for a way so assign only certain arrays as required. For instance, I might only want to assign the settings values from all defaultRenderNodes.

 

Thank you,

 

Craig

0 Likes
Accepted solutions (1)
697 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

First you need to import your dict from the json file.

 

Then you either iterate through keys and then call values in the loop:

 

import maya.cmds as mc

dict = importedDictionary

for key in dict:

    cmds.setAttr(key,dict[key])

 

 

Or you unpack your dict with the .items() function first:

 

import maya.cmds as mc

dict = importedDictionary

for key,value in dict.items():

    cmds.setAttr(key,value)

 

 

The second is considered more readable and pythonic, but it doesn't really make a difference.

 

I hope this helps!

 

0 Likes
Message 3 of 3

craig_kane
Participant
Participant

Thanks Kahylan, worked perfectly! Appreciate the help.

0 Likes