Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Maya渲染设置问题_Python_Maya_Renderer - Fatal编程技术网

Python Maya渲染设置问题

Python Maya渲染设置问题,python,maya,renderer,Python,Maya,Renderer,我有两个问题,我不确定这是否可以通过使用python在场景中完成 我的Maya版本未安装任何Mental Ray。有时,当我打开文件(使用Mental Ray安装)时,会不断收到错误,例如: // Warning: file: /apps/Linux64/aw/maya2014/scripts/others/supportRenderers.mel line 77: The renderer "mentalRay" used by this scene, is not currently ava

我有两个问题,我不确定这是否可以通过使用python在场景中完成

我的Maya版本未安装任何Mental Ray。有时,当我打开文件(使用Mental Ray安装)时,会不断收到错误,例如:

// Warning: file: /apps/Linux64/aw/maya2014/scripts/others/supportRenderers.mel line 77: The renderer "mentalRay" used by this scene, is not currently available. The Maya Software renderer will be used instead. //
// Error: file: /apps/Linux64/aw/maya2014/scripts/others/supportRenderers.mel line 82: setAttr: The attribute 'defaultRenderGlobals.currentRenderer' is locked or connected and cannot be modified. //
// Error: file: /apps/Linux64/aw/maya2014/scripts/others/unifiedRenderGlobalsWindow.mel line 415: The renderer mentalRay is not registered yet. //
// Error: line 1: The renderer mentalRay is not registered yet. // 
我尝试使用以下代码“纠正”问题:

list = cmds.listAttr("defaultRenderGlobals", l=True)

for item in list:
    cmds.setAttr("defaultRenderGlobals." + item, l=False)

mel.eval('updateCurrentRendererSel("unifiedRenderGlobalsRendererSelOptionMenu");')
mel.eval('loadPreferredRenderGlobalsPreset("mayaHardware");')
但是,如果我试图打开渲染设置,我会遇到另一个错误

//Error: Object ‘tabForm’ not found.
那个么,有什么方法可以在场景中修复这个问题吗

附上屏幕截图:

注意:请参阅本答案下面的“更新”部分,以找到完整的解决方案

为什么不尝试使用
setAttr
本身解锁并设置
currentRenderer
值呢

cmds.setAttr("defaultRenderGlobals.currentRenderer", l=False)    
cmds.setAttr("defaultRenderGlobals.currentRenderer", "mayaHardware", type="string")
出现错误
//错误:找不到对象“tabForm”。
因为无法加载渲染设置窗口,可能是因为未注册的mentalRay。因此,在更改当前渲染器之前,请避免调用以下内容:

mel.eval('updateCurrentRendererSel("unifiedRenderGlobalsRendererSelOptionMenu");')
mel.eval('loadPreferredRenderGlobalsPreset("mayaHardware");')
更新:

从问题中的更新和下面的注释中,我们了解到,这里的问题是Maya在遇到缺少渲染器或渲染设置错误时无法正确构造“渲染设置”窗口的UI。这导致无法构建父UI组件,如选项卡和框架。因此,在切换渲染器时,“渲染设置”UI会尝试将相应的设置加载到这些选项卡中,但找不到它们并停止

要解决这个问题,我们只需设置所需的渲染设置,完全删除“渲染设置”窗口的UI并重新加载即可。我为此编写了一个快速函数。这会解决它的

import maya.cmds as cmds
import maya.mel as mel


def remake_render_settings_ui(renderer="mayaSoftware"):
    """ Remakes the render settings window """
    # Unlock the render globals' current renderer attribute
    cmds.setAttr("defaultRenderGlobals.currentRenderer", l=False)    

    # Sets the current renderer to given renderer
    cmds.setAttr("defaultRenderGlobals.currentRenderer", renderer, type="string")

    # Deletes the render settings window UI completely
    if cmds.window("unifiedRenderGlobalsWindow", exists=True):
        cmds.deleteUI("unifiedRenderGlobalsWindow")

    # Remake the render settings UI
    mel.eval('unifiedRenderGlobalsWindow;')


if __name__ == "__main__":
    remake_render_settings_ui(renderer="mayaHardware")
警告:如果再次选择错误的渲染器,这将无法防止UI再次丢失。为了防止这种情况,最好使用渲染器的插件。在任何情况下,如果再次调用上述方法,则应修复窗口


希望这是有用的。

在安装了无Mental Ray插件的计算机中打开包含Mental Ray痕迹的场景文件时,渲染设置中会出现一些问题

出于某些原因,尽管在场景中的
defaultRenderGlobals
中解锁并设置了渲染器,但渲染设置仍将存在线程帖子或
kartikg3
答案中的注释中提到的问题

我找到了一个解决方法-

  • 解锁
    defaultRenderGlobals
  • 保存所述文件,删除任何现有的
    UnifiedEnderGlobalWindow
    UI
    +更多的mel命令
  • 重新加载/重新打开场景
在我看来,在场景中执行前2个步骤不会纠正“渲染设置”窗口中的问题,除非我通过打开新的文件会话关闭当前场景文件或重新打开文件本身

import maya.cmds as cmds
import maya.mel as mel

def unlockRenderer(renderer="mayaHardware2"):
    print "Unlocking and resetting current renderer"

    # Unlock the render globals' current renderer attribute
    cmds.setAttr("defaultRenderGlobals.currentRenderer", l=False)    

    # Sets the current renderer to given renderer
    cmds.setAttr("defaultRenderGlobals.currentRenderer", renderer, type="string")

def saveFile():
    # Prompts User to resave the file, removing traces of Mental Ray
    mel.eval('SaveSceneAs;')

def reloadScene():
    recentFiles = []
    try:
        recentFiles = cmds.optionVar( query = 'RecentFilesList' )

    except:
        cmds.error("No recent files found!")

    curFile = cmds.file(query =True, loc = True)

    if curFile == "unknown":
        cmds.confirmDialog(title = 'Reload Scene', message = ('Reload Last Opened Scene?\n\n' + recentFiles[len(recentFiles)-1]), button = ['Cancel','OK'], defaultButton = 'OK', cancelButton = 'Cancel', dismissString = 'Cancel' )
        cmds.file( str(recentFiles[len(recentFiles)-1]), force = True, open = True)
        print "Opening Last Recent File - ", recentFiles[len(recentFiles)-1]
    else:
        cmds.confirmDialog(title = 'Reload Scene', message = ('Reload Current Scene?\n'), button = ['Cancel','OK'], defaultButton = 'OK', cancelButton = 'Cancel', dismissString = 'Cancel' )
        curFileLoc = cmds.file(query = True, location = True)
        cmds.file( curFileLoc , force = True, open = True)
        print "Re-Opening current file - ", curFileLoc

def main():
    unlockRenderer(renderer="mayaHardware2")
    saveFile()
    if cmds.window("unifiedRenderGlobalsWindow", exists=True):
        cmds.deleteUI("unifiedRenderGlobalsWindow")
    mel.eval('resetAE()')
    mel.eval('buildNewSceneUI;')
    reloadScene()

main()

需要注意的是-有时,未找到一些错误,例如
\//错误:文件:/apps/Linux64/aw/maya2014/scripts/others/unifiedRenderGlobalsWindow.mel第1074行:setParent:对象“unifiedRenderGlobalsWindow”//。它可能会因场景文件的不同而不同

请告诉我下面的答案是否适合您。如果它没有共享您得到的确切错误,可能还有渲染设置窗口的屏幕截图。@kartikg3顺便说一句,当我尝试您的解决方案时,我不再看到
//错误:第1行:渲染器mentalRay尚未注册//但每当我打开渲染设置时,无论选择哪个渲染器,我都会得到与粘贴的屏幕截图相同的效果。。话虽如此,我看不到任何错误或任何东西在编辑银行的回复我。当我尝试您的命令时,我遇到了这个问题,请在我尝试打开渲染设置时查看我的屏幕截图。这就是我实现mel命令的原因。即便如此,在使用我的mel命令时,有时我在渲染之间切换时,其选项卡/内容不会相应更新,并且还会显示
//错误:找不到对象“tabForm”。
在编辑器中,您使用的Maya版本,您尝试打开的场景文件是使用哪个版本的Maya创建的?我使用的是Maya 2014版。我试图打开的场景文件很可能是在Maya 2012中创建的(加载了mentalray),因此我看到以下消息的原因
//警告:file:/apps/Linux64/aw/maya2014/scripts/others/supportrenders.mel line 77:此场景使用的渲染器“mentalray”当前不可用。将改用Maya软件渲染器//尝试:运行上述脚本,然后将文件另存为副本,重新启动maya。然后打开副本。我稍后会尝试,但我能否询问是否可以不保存文件并重新启动Maya?不可能“修复”场景中的所有内容?