Search code examples
pythonmayapymel

How can i query the undoInfo in a python string in maya?


I'm developing a tool for maya and would like to query the undo history in a python string to process it. I've found that undoInfo( q=True, pq=True ) displays the undo history in maya's script console, but doesn't return anything so i can't store this result in a variable.

Is there another command to get this information, and if not, is there a way for me to get the result displayed in maya's console?

Thanks in advance.


Solution

  • This isn't the cleanest method, but you can use scriptEditorInfo to write the undoInfo output to a temporary file like so:

    pm.scriptEditorInfo(historyFilename="/tmp/undoInfoRecord.txt", writeHistory=True)
    pm.undoInfo(q=True, pq=True)
    pm.scriptEditorInfo(writeHistory=False)
    
    undoInfoLines = []
    with open('/tmp/undoInfoRecord.txt') as f:
        undoInfoLines = f.readlines()
    undoInfoLines = undoInfoLines[2:-1]  # Remove scriptEditorInfo outputs and undoInfo command