本文整理汇总了Python中maya.cmds.undo函数的典型用法代码示例。如果您正苦于以下问题:Python undo函数的具体用法?Python undo怎么用?Python undo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了undo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testUndoRedo
def testUndoRedo(self):
"""Tests that adaptors work with undo/redo."""
cmds.file(new=True, force=True)
cmds.group(name="group1", empty=True)
adaptor = UsdMaya.Adaptor("group1")
self.assertEqual(adaptor.GetAppliedSchemas(), [])
# Do a single operation, then undo, then redo.
adaptor.ApplySchema(UsdGeom.ModelAPI)
self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"])
cmds.undo()
self.assertEqual(adaptor.GetAppliedSchemas(), [])
cmds.redo()
self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"])
# Do a compound operation, then undo, then redo.
cmds.undoInfo(openChunk=True)
adaptor.ApplySchema(UsdGeom.MotionAPI).CreateAttribute(
UsdGeom.Tokens.motionVelocityScale).Set(0.42)
self.assertEqual(adaptor.GetAppliedSchemas(),
["GeomModelAPI", "MotionAPI"])
self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute(
UsdGeom.Tokens.motionVelocityScale).Get(), 0.42)
cmds.undoInfo(closeChunk=True)
cmds.undo()
self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"])
self.assertFalse(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute(
UsdGeom.Tokens.motionVelocityScale))
self.assertIsNone(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute(
UsdGeom.Tokens.motionVelocityScale).Get())
cmds.redo()
self.assertEqual(adaptor.GetAppliedSchemas(),
["GeomModelAPI", "MotionAPI"])
self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute(
UsdGeom.Tokens.motionVelocityScale).Get(), 0.42)
示例2: __exit__
def __exit__(self, exc_type, exc_value, traceback):
'''Close the opened chunk and undo everything that had been captured.'''
cmds.undoInfo(closeChunk=True)
try:
cmds.undo()
except RuntimeError:
pass
示例3: componentSelectionInOrder
def componentSelectionInOrder():
'''
Returns a list of the selected components in the order they were selected.
'''
# Get selection
selection = []
selectionAll = mc.ls(sl=1)
lastCommand = mc.undoInfo(q=True,un=True)
counter = 0
# Traverse undo list
while lastCommand.count('select'):
lastCommand = mc.undoInfo(q=True,un=True)
if lastCommand.count('select'):
selectElem = lastCommand.split(' ')
selection.append(selectElem[2])
mc.undo()
# Sort selection
selection.reverse()
realSelection = []
[realSelection.append(i) for i in selection if not realSelection.count(i)]
# Return result
return realSelection
示例4: jobUndo
def jobUndo(*args):
# need to reset globals if an undo is detected
que = cmds.undoInfo(q=1, rn=1)
if 'import curveSoftSelect as css' in que or 'jobValue' in que:
cmds.undo()
killValueJob()
activateValueJob()
示例5: orientJoints
def orientJoints(s):
"""
Face joints in the correct direction.
"""
sel = cmds.ls(sl=True)
err = cmds.undoInfo(openChunk=True)
try:
markers = s.markers
joints = markers.keys()
with ReSeat(joints):
for j in joints:
m = markers[j]
if cmds.objExists(m.marker) and cmds.objExists(j):
with Isolate(j):
m.setJoint()
try:
cmds.makeIdentity(
j,
apply=True,
r=True) # Freeze Rotations
except RuntimeError:
pass
else: # User deleted marker / joint. Stop tracking.
m.removeMarker()
del markers[j]
cmds.select(sel, r=True)
except Exception as err:
raise
finally:
cmds.undoInfo(closeChunk=True)
if err: cmds.undo()
示例6: rsReAtt
def rsReAtt():
l_oSels = rsObjList()
l_AttributeList = (cmds.textScrollList("rsAttributeScroll", query=True, allItems=True))
for s_Att in l_AttributeList:
s_orig = l_oSels[0] + "." + s_Att
i_LockState = cmds.getAttr(s_orig, lock=True)
if i_LockState:
cmds.setAttr(s_orig, lock=False)
l_paramDest = cmds.listConnections(s_orig, plugs=True, destination=True, source=True)
l_paramDestLock = []
if l_paramDest:
for z in range(len(l_paramDest)):
l_paramDestLock.append(cmds.getAttr(l_paramDest[z], lock=True))
if l_paramDestLock[z]:
cmds.setAttr(l_paramDest[z], lock=False)
cmds.deleteAttr(l_oSels[0], at=s_Att)
cmds.undo()
if l_paramDest:
for z in range(len(l_paramDest)):
l_paramDestLock.append(cmds.getAttr(l_paramDest[z], lock=True))
if l_paramDestLock[z]:
cmds.setAttr(l_paramDest[z], lock=True)
if i_LockState:
cmds.setAttr(s_orig, lock=True)
cmds.select(cl=True)
cmds.select(l_oSels[0], r=True)
return True
示例7: wrapper
def wrapper(*args, **kw):
with self:
try:
return f(*args, **kw)
except:
if rollback:
mc.undo()
raise
示例8: bakeShader
def bakeShader(self, shader, cmd):
self.createShaders()
cmds.undoInfo(openChunk=True)
self.assignShader(shader)
self.setAttributes(shader)
mel.eval(cmd)
cmds.undoInfo(closeChunk=True)
cmds.undo()
示例9: fix_shaders
def fix_shaders():
"""
Fixing a bug in maya where a referenced maya file loses it's shaders. Mesh needs to be selected
"""
get_selected(scriptEditorWarning=True)
mel.eval("sets -e -forceElement initialShadingGroup;")
cmds.undo()
pm.select(cl=1)
示例10: undoSel
def undoSel():
sel = cmds.ls(sl=True)
info = cmds.undoInfo(q=True, un=True)
if 'selectKey' in info:
return None
elif 'select' in info:
cmds.undo()
cmds.select(clear=True)
cmds.select(sel)
return True
示例11: test_undoPerformance
def test_undoPerformance( self ):
import time
iterations = 35
maxdepth = 3
totalops = 0
all_elapsed = [list(),list()]
for undoEnabled in range( 2 ):
undo = ""
if not undoEnabled:
undo = "Undo disabled"
cmds.undoInfo( st=undoEnabled )
# decorated !
starttime = time.time()
numops = TestUndoPerformance._recurseUndoDeco( iterations, 0, maxdepth )
totalops += numops
elapsed = time.time() - starttime
all_elapsed[undoEnabled].append( elapsed )
print >> sys.stderr, "UNDO: DECORATED %s: %i ops in %f s ( %f / s )" % ( undo, numops, elapsed, numops / elapsed )
starttime = time.time()
numops = TestUndoPerformance._recurseUndo( iterations, 0, maxdepth )
totalops += numops
elapsed_deco = elapsed
elapsed = time.time() - starttime
all_elapsed[undoEnabled].append( elapsed )
print >> sys.stderr, "UNDO: MANUAL %s: %i ops in %f s ( %f / s )" % ( undo, numops, elapsed, numops / elapsed )
starttime = time.time()
print >> sys.stderr, "UNDO: DECORATED is %f %% faster than manually implemented functions !" % ( 100 - ( elapsed_deco / elapsed ) * 100 )
if undoEnabled:
cmds.undo()
cmds.undo()
cmds.redo()
cmds.redo()
elapsed = time.time() - starttime
print >> sys.stderr, "UNDO: CALL TIME: %i operations in %f s ( %f / s )" % ( totalops, elapsed, totalops / elapsed )
#END if undo enabled
# END for each undo queue state
ratio = 100.0 - ( ( all_elapsed[0][0] / all_elapsed[1][0] ) * 100 )
difference = all_elapsed[1][1] - all_elapsed[0][1]
# RATIOS between enabled undo system and without
print >> sys.stderr, "UNDO: RATIO UNDO QUEUE ON/OFF: %f s (on) vs %f s (off) = %f %% speedup on disabled queue ( difference [s] = %f )" % (all_elapsed[1][0], all_elapsed[0][0], ratio, difference )
示例12: mel_handler
def mel_handler(self, input_str):
prev_chunk = cmds.undoInfo(q=True, chunkName=True)
cmds.undoInfo(openChunk=True)
try:
execInMain(partial(mel.eval, input_str))
cmds.repeatLast(addCommand=input_str)
cmds.undoInfo(closeChunk=True)
except:
cmds.undoInfo(closeChunk=True)
if not cmds.undoInfo(q=True, chunkName=True) == prev_chunk:
cmds.undo()
raise
示例13: moveToBottom
def moveToBottom(attribute):
"""
Move specified attribute to the bottom of the channel box
"""
# Determine object and attribute names from input argument
obj = attribute.split(".")[0]
attr = attribute.split(".")[-1]
# Delete attribute temporarily
mc.deleteAttr(obj, attribute=attr)
# Undo deletion
mc.undo()
示例14: test_removeChild
def test_removeChild(self):
base = nt.createNode("base" , "transform")
trans = nt.createNode("base|trans", "transform")
mesh = nt.createNode("base|mesh", "mesh")
for item in [trans, mesh]:
removeditem = base.removeChild(item, allowZeroParents=True)
# PATHS ARE INVALID NOW - object is nowhere to be found
assert not removeditem.isValid() and removeditem.isAlive()
cmds.undo()
assert removeditem.isValid() and removeditem.isAlive()
示例15: py_handler
def py_handler(self, input_str):
prev_chunk = cmds.undoInfo(q=True, chunkName=True)
cmds.undoInfo(openChunk=True)
try:
execInMain(input_str)
setattr(__main__, "last_py_cmd", input_str)
cmds.repeatLast(addCommand='python("execInMain(last_py_cmd)")')
cmds.undoInfo(closeChunk=True)
except:
cmds.undoInfo(closeChunk=True)
if not cmds.undoInfo(q=True, chunkName=True) == prev_chunk:
cmds.undo()
raise