cmdx.Context
Improved support for reading plugs at arbitrary times.
Say you have a node with an animated `translateX`
py
tx = cmdx.create_node("animCurveTL")
tx.keys(times=[1, 2, 3, 4], values=[0, 10, 20, 33], interpolation=cmdx.Smooth)
node = cmdx.create_node("transform")
node["tx"] << tx["output"]
And you wanted to know the value at frame 3. You could either..
py
cmds.currentTime(3)
assert node["tx"].read() == 20
cmds.currentTime(1) Restore time
Which would alter the global timeline for everything in Maya, and provide you with the value for this one node.
Or you could..
py
assert node["tx"].read(time=3) == 20
Which is great for one-off reads, but once you get just a few of these, passing in an explicit time each time can get tedious, hard to read.
Since cmdx 0.4.5 and Maya 2018+ you can now leverage Maya's [`MDGContext`](https://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__py_ref_class_open_maya_1_1_m_d_g_context_html).
py
context = om.MDGContext(om.MTime(3, unit=om.MTime.uiUnit()))
context.makeCurrent()
assert node["tx"].read() == 20
om.MDGContext.kNormal.makeCurrent() Restore "context"
On top of this, you can also leverage the new context manager, `cmdx.DGContext` with the optional `cmdx.Context` alias.
py
with cmdx.Context(3):
assert node["tx"].read() == 20
Thanks to monkeez for this addition!