Physics Field Toggling Tool

Hi all,

Here’s a small simple tool for you to:

  • Quick toggling physic force fields!

Just copy the following script into your Maya script editor tab (python) and run it. And you should see a small window pops up with all your fields listed as checkbox!

# RagdollDynamics: Field Toggler

from maya import cmds
from ragdoll.vendor import cmdx
from functools import partial


def get_fields():
    for solver in cmdx.ls(typ="rdSolver"):
        a = str(solver) + ".owner"
        for fd in cmds.listConnections(a, s=1, t="field"):
            yield solver, cmdx.encode(fd)


def ui_enable_field(field, solver, *args):
    with cmdx.DagModifier() as mod:
        index = solver["inputFields"].next_available_index()
        mod.connect(field["message"], solver["inputFields"][index])


def ui_disable_field(i, field, *args):
    conn = iter(cmds.listConnections(i, c=1))
    for p, f in zip(conn, conn):
        if f == field:
            cmds.disconnectAttr(f + ".message", p)
            return


def make_gui():
    name = "rdSolverFieldsGUI"
    if cmds.window(name, q=1, ex=1):
        cmds.deleteUI(name)
    window = cmds.window(name)
    cmds.columnLayout(adjustableColumn=1)
    for s, f in get_fields():
        _i = s.shortestPath() + ".inputFields"
        v = f.name() in (cmds.listConnections(_i) or [])
        onc = partial(ui_enable_field, f, s)
        ofc = partial(ui_disable_field, _i, f.name())
        cmds.checkBox(label=f.name(), v=v, onc=onc, ofc=ofc)
    cmds.showWindow(window)


make_gui()

Quick walkthrough :slight_smile:

Hope you find this useful :heart:

9 Likes

Thank you for the script! Works great!

However, it seems to not work with the ragdoll rigs referenced into scenes. Each toggle multiplies the effect of the field, instead of disabling it. It seems the Message output of the Field gets reconnected into a new input instead of disconnecting in the Node editor.

Also on the side note - noticed a strange behaviour with fields in general - putting the magnitude to 0 does not seem to completely disable it. The behaviour of the marker is different between magnitude at 0 and if the field was deleted or the Message output disconnected. This occurs at least with Newton field and a marker used as source.

Sounds like a good topic for a new thread, with an example to go with it if possible!

1 Like

this is very handy !!! thanks…

What I was doing manually was setting it up the magnitude and vector to 0… but this is great to test and find the best values… !

Thanks