0.4.5
cmdx.Context
Improved support for reading plugs at arbitrary times.
Say you have a node with an animated translateX
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..
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..
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
.
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.
with cmdx.Context(3):
assert node["tx"].read() == 20
Thanks to @monkeez for this addition!