[Maya-Python] Playblasting in standalone

2,668 views
Skip to first unread message

Marcus Ottosson

unread,
Aug 27, 2015, 3:40:53 AM8/27/15
to python_in...@googlegroups.com

The cmds.playblast works well when run from Maya in standalone, but I’m having trouble specifying which camera to playblast through.

From the GUI, I typically use..

import maya.cmds
maya.cmds.lookThru("myCamera")
maya.cmds.playblast()

But in standalone, this gives me an error.

>>> maya.cmds.lookThru("persp")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: There is no active view.

Are there any other methods of specifying a camera for playblast?

--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Aug 27, 2015, 7:29:35 AM8/27/15
to python_in...@googlegroups.com

To clarify what I mean by “standalone”

$ mayapy
>>> import maya.standalone
>>> maya.standalone.initialize()
>>> import maya.cmds
>>> maya.cmds.lookThru("modelPanel1", "top")
>>> maya.cmds.setFocus("modelPanel1")
>>> maya.cmds.playblast()

This works in GUI mode, but not in standalone i.e. via command-line, so long as the panel itself is visible in Maya.

--
Marcus Ottosson
konstr...@gmail.com

Roy Nieterau

unread,
Aug 27, 2015, 7:36:06 AM8/27/15
to Python Programming for Autodesk Maya
Unfortunately it's not really obvious from any documentation.

It seems that when Maya is running in standalone mode it takes a 'renderable' camera to playblast.

For example try:
cams = cmds.ls(type='camera')
for cam in cams:
   
cmds.setAttr(cam + '.rnd', 0)

And then playblasting in standalone. You'll get a fatal error.
The trick is to only keep your preferred camera as a renderable camera.

cams = mc.ls(type='camera')
for cam in cams:
   
cmds.setAttr(cam + '.rnd', 0)
cmds.setAttr('myCamShape.rnd', 1)

This will ensure your standalone Maya will capture that camera.
In standalone you might not be saving your scene (batch playblast?), but if you don't want to mess to much with the scene state you could wrap your playblast in a context. Like so:

import contextlib

@contextlib.contextmanager
def solo_renderable(solo_cam):

   
# Disable all cameras as renderable
   
# and store the original states
    cams
= cmds.ls(type='camera')
    states
= {}
   
for cam in cams:
        states
[cam] = mc.getAttr(cam + '.rnd')
       
cmds.setAttr(cam + '.rnd', 0)
       
   
# Change the solo cam to renderable
   
cmds.setAttr(solo_cam + '.rnd', 1)

   
try:
       
yield
   
finally:
       
# Revert to original state
       
for cam, state in states.items():
           
cmds.setAttr(cam + '.rnd', state)

with solo_cam('myCamShape'):
    cmds
.playblast()

Marcus Ottosson

unread,
Aug 27, 2015, 8:49:04 AM8/27/15
to python_in...@googlegroups.com
That (surprisingly) works! Thanks Roy. :)

--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/19702d7f-db58-4cdf-ab1c-060284fa0da4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Yingjie He

unread,
Mar 4, 2018, 9:53:29 AM3/4/18
to Python Programming for Autodesk Maya
Hi,Roy.When i use playblast command  in "standalone",how can i  make “FilmGate” visible?

在 2015年8月27日星期四 UTC+8下午7:36:06,Roy Nieterau写道:

lmnm...@gmail.com

unread,
Apr 2, 2019, 2:41:08 PM4/2/19
to Python Programming for Autodesk Maya
在 2015年8月27日星期四 UTC+8下午3:40:53,Marcus Ottosson写道:
Can you publish successful code
Reply all
Reply to author
Forward
0 new messages