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:

7 Likes