Playback cannot be initiated from within Python Script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The code below creates 25 cylinders and drops them to the ground using Bullet gravity. If I execute the whole script at once, then the cylinders are created but are not dropped to the ground. What will work is executing all but the last line (creating the cylinders but not dropping them), pausing, and then running the last line (dropping the cylinders).
I would like to be able to run the whole script with one click. I have done this successfully without the use of Bullet. Any thoughts are appreciated!
While I'm at it, another problem: I want to have a panel layout with the scene and the script editor side-by-side. I can achieve this, but whenever I start an animation, the scene goes full screen (removing the script editor from the panel layout). Any thoughts on what could be causing this behavior?
Code:
import maya.cmds as cmds
cmds.file(new=True, force=True)
import maya.app.mayabullet.BulletUtils as BulletUtils
BulletUtils.checkPluginLoaded()
import maya.app.mayabullet.RigidBody as RigidBody
for x in range (1, 25):
cmds.polyCylinder()
shape = 'pCylinder%d' % (x)
cmds.move( x / 4.0 * (-1) ** x, 15 + x * 2, shape, r = True)
RigidBody.CreateRigidBody(True).executeCommandCB()
cmds.playbackOptions(ast = 1, aet = 44)
cmds.play()