使用此命令:
cmds.file(rename = "newName.mb")
不会在窗口顶部的菜单栏中显示新名称。它仍然显示旧名称,但添加星号*表示它已被更改。
问题是这对用户来说很困惑。该文件将保存在不同的路径中,但在您执行此操作之前,您不会知道。
如果重命名不是<?p?
,如何更新顶部显示的名称答案 0 :(得分:1)
我通过更改选择来处理此问题,这会强制Maya更新标题栏(从而显示新文件名):
cmds.file(rename = "newName.mb")
cur_selection = cmds.ls(sl=True) # Save current selection
cmds.select('renderPartition') # Select something (anything) the user doesn't already have selected
cmds.select(cur_selection) # Restore user's selection
答案 1 :(得分:0)
您可以使用PySide实现这一目标,自2014年以来,它本身随Maya一起提供。您可以使用Pyside在Maya中自定义几乎所有内容。
以下是更改窗口标题的代码:
import maya.cmds as cmds
from PySide import QtCore, QtGui
from maya import OpenMayaUI as omui
from shiboken import wrapInstance
def getMayaWindow():
omui.MQtUtil.mainWindow()
ptr = omui.MQtUtil.mainWindow()
return wrapInstance(long(ptr), QtGui.QWidget)
newPath = r"C:\Users\pfruchet\Desktop\NewSceneName.ma"
mayaWindow = getMayaWindow()
print mayaWindow.windowTitle() #Prints the window title with your original scene path
cmds.file(rename = newPath)
print mayaWindow.windowTitle() #Prints the window title with your original scene path
print cmds.file(query=True, sn=True) #But Prints C:/Users/pfruchet/Desktop/NewSceneName.ma ---> Scene name changed but not updated in window title
mayaWindow.setWindowTitle(r"Autodesk Maya 2014: " + newPath) #here is the magic
print mayaWindow.windowTitle() #Prints Autodesk Maya 2014: C:\Users\pfruchet\Desktop\NewSceneName.ma
mayaWindow.setWindowModified(False)
最后一行允许您显示或隐藏&#34; *&#34;在文件路径之后。
<强>输出:强>
Autodesk Maya 2014: C:\Users\pfruchet\Desktop\OriginalScene.ma
Autodesk Maya 2014: C:\Users\pfruchet\Desktop\OriginalScene.ma
C:/Users/pfruchet/Desktop/NewSceneName.ma
Autodesk Maya 2014: C:\Users\pfruchet\Desktop\NewSceneName.ma
一些参考文献:
Autodesk doc: Working with PySide in Maya如何通过添加可怕的样式表来破坏maya。
Pyside doc: QWidget如果你想尝试其他东西(你可以明显改变窗口图标)