Importing and Patching#

Paya works by swapping-out PyMEL’s classes on-the-fly using a fast runtime patch. To apply the patch, import paya.runtime and use it as a context manager:

# Order of imports doesn't matter
import pymel.core as pm
import paya.runtime

loc = pm.PyNode('locator1')
print(type(loc))
# Result: <class 'pymel.core.nodetypes.Transform'>

with paya.runtime:
    loc = pm.PyNode('locator1') # re-instantiate
    print(type(loc))
    # Result: <class 'paya.runtime.nodes.Transform'>

# Patching is reversed as soon as the block is exited:
loc = pm.PyNode('locator1')
print(type(loc))
# Result: <class 'pymel.core.nodetypes.Transform'>

Notice that, when called inside the context block, type() returns a different class: paya.runtime.nodes.Transform. This is a subclass of the original pymel.core.nodetypes.Transform, with added rigging methods such as createOffsetGroups(). PyMEL’s attribute, component and data classes are extended in the same way.