I put together a Bullet example for you, and then realised you were using
the system prior to Bullet being introduced to Maya, so I’ll post both
examples for future readers.

So I think you’re doing it right, at least it appears to be designed for
use in this way. If so, it isn’t doing what it’s supposed to.

import maya.cmds as mc

mc.polySphere()
mc.rigidBody()# mc.select(clear=1)
mc.gravity()

Firstly, I expect you’ll need to actually have your object selected, as
forces are applied per-rigid. The problem however is that when applying
gravity via Python, it generates this extra geoConnector node for some
reason. :/

[image: image.png]

You can “repair” this manually, and end up with what you get when using the
Maya Fields menu, by connecting the missing bits like this.

import maya.cmds as mc

mc.polySphere()
rigid = mc.rigidBody()
_, gravity = mc.gravity()
cmds.connectAttr(gravity + ".outputForce[0]", rigid + ".inputForce[0]")
cmds.connectAttr(rigid + ".fieldData", gravity + ".inputData[0]", force=True)

And finally, here’s the Bullet equivalent, plus a ground plane.

from maya import cmds as mcfrom maya.app.mayabullet import RigidBody

cmds.file(new=True, force=True)
mc.polySphere()
cmds.move(0, 5)
_, rigid = RigidBody.CreateRigidBody(True).executeCommandCB()
cmds.setAttr("bulletSolver1.groundPlane", True)
cmds.setAttr(rigid + ".colliderShapeType", 2)  # Sphere

These were tested on Maya 2020.

On Wed, 2 Feb 2022 at 04:25, Gray Marshall <[email protected]> wrote:

> This is silly, but I can't figure it out...
>
> When I do this (and much more) in the GUI, it works fine.. the ball falls
> when I hit "Play".
> When I try to do the same thing with the code below, it doesn't work.  It
> looks exactly the same in the Outliner & in the Attribute Editor, but no
> gravity.  Thoughts?
>
> import maya.cmds as mc
>
> mc.polySphere()
> mc.rigidBody()
> mc.select(clear=1)
> mc.gravity()
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/c63567ec-5594-4076-a3cf-ae87b6a8c9cen%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/c63567ec-5594-4076-a3cf-ae87b6a8c9cen%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAx5kv31Errd6LK_Fe5wbuERROxiUBWFhbuC%2Bs3nC0a6A%40mail.gmail.com.

Reply via email to