Is there a way to render by selected object in Python?

412 views
Skip to first unread message

I73

unread,
Aug 12, 2016, 4:25:35 PM8/12/16
to Python Programming for Autodesk Maya
I am trying to render the selected object in the scene, unfortunately the 'Render-> 'Render selected objects only' doesn't output to the script editor so I can't follow the MEL example. 
Is there anyone that has a working example or command I can use to get a render by selected object?

render = cmds.render('persp', x=300, y=300, abortMissingTexture=True)


Andrew Hazelden

unread,
Aug 12, 2016, 5:28:21 PM8/12/16
to Python Programming for Autodesk Maya
The Maya Render View's "Render Selected Objects Only" menu item is defined and controlled in the following MEL file:
/Applications/Autodesk/maya2017/Maya.app/Contents/scripts/others/renderWindowPanel.mel

Besides the menuItem entry, there are two MEL other functions in this script that refer to this specific rendering feature which are "switchSelectObj()" and "refreshRenderMenu()".

Both functions use MEL with an int based optionVar named "renderViewRenderSelectedObj" to turn this rendering mode on and off:
optionVar -intValue renderViewRenderSelectedObj $var;

Regards,
Andrew Hazelden

I73

unread,
Sep 7, 2016, 5:23:30 PM9/7/16
to Python Programming for Autodesk Maya
Hey Andrew, thanks for the reply, and sorry for the late reply. 
So I am still not fully understanding what the render view is doing. Am I going to have to use mel.eval to call renderViewRenderSelectedObj? Or can I preform this in python?
Or is there a better way to render out the selected objet only by the cmds.render('persp', x=300, y=300, abortMissingTexture=True)
Thanks! 

Wesley Keeling

unread,
Sep 7, 2016, 5:36:38 PM9/7/16
to python_in...@googlegroups.com
It works when I call the eval, but it only works when I first manually render the scene after executing:
import maya.mel as mel
mel.eval('int $var = 0; if( `optionVar -exists renderViewRenderSelectedObj` ) { $var = (! `optionVar -q renderViewRenderSelectedObj`); } optionVar -intValue renderViewRenderSelectedObj $var;')

It seems to not want to refresh the renderer settings till I manually render.  

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d9f2e7a6-e1bd-4914-b760-305da9d74ebd%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Wesley Keeling

unread,
Sep 7, 2016, 6:04:14 PM9/7/16
to python_in...@googlegroups.com
Well I have a few 'hacks' for rendering the selected object, I would love to not use mel. 

mel.eval('optionVar -intValue renderViewRenderSelectedObj 1;')
mel.eval('renderWindowRender redoPreviousRender renderView;')
mel.eval('prepareRender -invokePreRenderFrame;')
mel.eval('prepareRender -invokePostRenderFrame;')
mel.eval('updateEditorFeedbackRenderLayer RenderLayerTab defaultRenderLayer;')

If there is a better way, please feel free to tell me :) 

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

Andrew Hazelden

unread,
Sep 9, 2016, 1:40:59 PM9/9/16
to Python Programming for Autodesk Maya
For setting the specific optionVar value you could skip MEL and use this Python command instead:

# Enable the "renderViewRenderSelectedObj" optionVar using Python
import maya.cmds as cmds
cmds.optionVar(intValue=('renderViewRenderSelectedObj', 1))


Regards,
Andrew Hazelden
Reply all
Reply to author
Forward
0 new messages