Changing image format in mentalray

1,096 views
Skip to first unread message

jbra...@gmail.com

unread,
Jun 26, 2009, 2:36:30 PM6/26/09
to python_inside_maya
Happy Friday everyone!

I'm hoping I'm just completely missing the mark here. I'm reworking
some auto-scene setup scripts for my artists and for the current job
we're using mostly mentalray instead of renderman. I need to switch
the image format to EXR.

The image formats translate to numerical values:
mentalrayFormats = {'pic':1, 'rla':2, 'tif':3, 'rgb':5, 'als':6, 'jpg':
8, 'eps':9,
'yuv':12, 'tga':19, 'bmp':20, 'psd':31, 'png':32}

mc.setAttr( 'defaultRenderGlobals.imageFormat', 3 ) #if I wanted to
switch to tif

Other than the formats in the dict above, all other formats are value
of 51... how do I switch to exr via python if all the other formats
default to 51? Is there another way to change this setting? Thanks
folks.

prabu raj

unread,
Jun 29, 2009, 7:45:42 AM6/29/09
to python_in...@googlegroups.com
Me too looking for a solution for the same problem.....

Sylvain Berger

unread,
Jun 29, 2009, 11:38:47 AM6/29/09
to python_in...@googlegroups.com
I don`t have maya in front of me, but maybe the flag you are looking for is in the mentalrayGlobals node.

My guess is that a mental ray only format will not be supported in the defaultRenderGlobal node... 51 may be ``all other mental ray format`` and the actual format supported by mental ray is in a mental ray node.

Good luck


On Mon, Jun 29, 2009 at 7:45 AM, prabu raj <praburaj...@gmail.com> wrote:
Me too looking for a solution for the same problem.....







--
"A pit would not be complete without a Freeman coming out of it."
The Vortigaunt

Justin Rosen

unread,
Jun 30, 2009, 3:50:33 AM6/30/09
to python_in...@googlegroups.com
The best place to find this info is in the mel code for the render
globals window
.../maya/scripts/others/createMayaSoftwareCommonGlobalsTab.mel

Here's a snippet of code I wrote in mel a while back accomplishing
what you're asking. I had created a menu option box that was
connected to the defaultRenderGlobals.

...
// Get global variables for mental ray file formats
global string $miImgFormat[];
// If the file format array has not been initialized yet, do so.
if(size( $miImgFormat ) == 0)
miCreateImageFormats();

global string $miImgExtLabel[]; // image extension label
global int $miImgExtNum[]; // numbers corresponding to
defaultRenderGlobals.imageFormat
global string $miMenuItem[]; // UI name for each menu item created

// Get the current image format
string $curImageFormat = `getAttr defaultRenderGlobals.imfkey`;
...


I could go into a more in depth explanation if you need. Or, I could
rewrite this in python. Let me know if this helps

Cheers,
Justin

John Riddle

unread,
Jun 30, 2009, 1:04:21 PM6/30/09
to python_in...@googlegroups.com
Awesome, getAttr defaultRenderGlobals.imfkey is exactly what I needed. No need for the python rewrite had just never encountered the imfkey attribute. =P Thanks a ton!

Justin Israel

unread,
Jul 17, 2012, 2:33:40 PM7/17/12
to python_in...@googlegroups.com
First you need to know the attribute names of everything, in order to set them. An easy way to dump the attributes visually for you to look at is:

    for a in sorted(cmds.listAttr ('defaultRenderGlobals')):
        print a

You already figured out "imfkey" and could set that via:

    cmds.setAttr ('defaultRenderGlobals.imfkey', "exr", type="string")

Looking through that sorted output of attributes, you will find "imageFilePrefix". That is the attribute for your File name prefix. You need to use the setAttr command and also tell it that the value is a string (the default expects an int)

cmds.setAttr("defaultRenderGlobals.imageFilePrefix", '%c/%s_%l', type="string")

Now for the other two attributes, they are a different story. They actually aren't direct attributes of the defaultRenderGlobals. You have to access them on the mentalrayGlobals. 

    for a in sorted(cmds.listAttr ('mentalrayGlobals')):
        print a

We find "imageCompression" and "compressionQuality". The quality is a simple number:

    cmds.setAttr("mentalrayGlobals.compressionQuality", 10)

But the compression value is not actually a string name. Its an index number related to the position of the value in the list. This is because there are different options for different image formats. "zip" is at index 4 (list indexes start at 0), so you can set it by passing the index:

    cmds.setAttr("mentalrayGlobals.imageCompression", 4)

Hope that helps!


On Tue, Jul 17, 2012 at 9:25 AM, Daz <dariu...@gmail.com> wrote:
Heya

Im trying to do the exact same thing + set zip as compression and prefix to %c/%s_%l... any chance to get some help with it and python? :S I got as far as 

cmds.getAttr ('defaultRenderGlobals.imfkey')
# Result: exr #
// Result: scriptEditorPanel1Window|TearOffPane|scriptEditorPanel1|formLayout37|formLayout39|paneLayout1|formLayout40|tabLayout2|formLayout54|cmdScrollFieldExecuter11 //

 but ehh im green in it ! :(

Thanks for help in advance :) 


--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe

Justin Israel

unread,
Jul 19, 2012, 12:55:21 PM7/19/12
to python_in...@googlegroups.com
Well you can start by using the Node reference to look for basic types and their attributes:

And you can also play around with wildcard ls commands:

cmds.ls('*Globals*')
# Result: [u'defaultHardwareRenderGlobals', u'defaultRenderGlobals', u'hardwareRenderGlobals', u'hardwareRenderingGlobals', u'mentalrayGlobals', u'renderGlobalsList1', u'strokeGlobals'] # 

cmds.ls('*Quality*')
# Result: [u'defaultRenderQuality'] # 


On Tue, Jul 17, 2012 at 12:53 PM, Daz <dariu...@gmail.com> wrote:
Hello

Thanks very much for help ! I got it finnaly to work and also special thanks to Kurian O.S for email help ! 


Code


import maya.cmds as cmds



cmds.setAttr("defaultRenderGlobals.imageFilePrefix", '%c/%s_%l', type="string")
cmds.setAttr("defaultRenderGlobals.imfkey", "exr", type="string")
cmds.setAttr("defaultRenderGlobals.imageFormat", 51)
cmds.setAttr("mentalrayGlobals.imageCompression", 4)
cmds.setAttr("defaultRenderGlobals.multiCamNamingMode", 1)
cmds.setAttr("defaultRenderGlobals.bufferName", "<RenderPass>", type='string')
cmds.setAttr("defaultRenderGlobals.enableDefaultLight", 0)

On a side note I realised that you can get a lot of data out of 

for a in sorted(cmds.listAttr ('mentalrayGlobals')):
      print a

Where can I read about other commands that I could list with options ? I'm trying to find Quality tab for mr... I know I can probably find it in help but ahhh I'm still looking :) I also can find it down in maya/scripts/other... not sure tho.

Thanks, bye.
Reply all
Reply to author
Forward
0 new messages