python。如何重定向玛雅历史?

python. How to redirect Maya history?

历史选项卡中打印所有 Maya 脚本日志和错误。这是所有命令和 python 脚本的输出。

为了更好地调试脚本,我希望所有日志都发送到服务器上的某个地方。如何拦截输出并将其发送到您的脚本。然后我会做所有必要的事情,输出要么是远程控制台,要么是服务器文件中的某个地方。

拦截输出的任务。怎么做?

听起来您需要像 Sentry 这样的实时错误跟踪器 ,在 Sentry 中,正是出于这个原因而制作的日志记录模块,与更丰富的 error/debug 处理

进行通信 Server/Client logging

此处是 Rerouting Maya 脚本编辑器到终端的示例

您还可以使用 Maya 的 scriptEditorInfo 命令重定向脚本编辑器历史记录 here:

这个用法的示例如下:

import maya.cmds as cmds
outfile = r'/path/to/your/outfile.txt'

# begin output capture
cmds.scriptEditorInfo(historyFilename=outfile, writeHistory=True)

# stop output capture
cmds.scriptEditorInfo(writeHistory=False)

还有 cmdFileOutput,您可以通过 MAYA_CMD_FILE_OUTPUT 的注册表项交互调用或 enable/disable,文档 here

最后,您可以使用 -log 标志将输出 Window 文本写入另一个位置来增强 Maya 开始。但是,有了这个,您不会得到脚本编辑器的输出,但考虑到您要记录的内容,这可能是您想要的。