Reputation: 649
I had 2 questions in which I am not sure if this can by done in-scene using python.
My Maya version is not installed with any Mental Ray. There are times in which when I opened files (that was installed with Mental Ray), I keep getting errors such as:
// 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. //
I tried using the following code to 'rectify' the issue:
list = cmds.listAttr("defaultRenderGlobals", l=True)
for item in list:
cmds.setAttr("defaultRenderGlobals." + item, l=False)
mel.eval('updateCurrentRendererSel("unifiedRenderGlobalsRendererSelOptionMenu");')
mel.eval('loadPreferredRenderGlobalsPreset("mayaHardware");')
but then I will get another bunch of error if I tried to open up my Render Settings
//Error: Object ‘tabForm’ not found.
And so, are there any ways in which this can be remedied in-scene
Attached is the screenshot:
Upvotes: 1
Views: 6458
Reputation: 649
There are a few problems that arises in the Render Settings while opening a scene file that contains traces of Mental Ray in a machine installed with no Mental Ray plugin
For some reasons, despite unlocking and setting a renderer in the defaultRenderGlobals
in the scene, the render settings will continue to have problems as mentioned in the thread post or comments in kartikg3
answer.
I found a workaround which is -
defaultRenderGlobals
unifiedRenderGlobalsWindow
UI
+ a few more mel commands Seems to me that doing the first 2 steps within the scene, it does not rectify the issues in the Render Settings window unless I either close the current scene file by opening a new file session or reopen the file itself...
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()
Something to note - At times, some errors such as #// Error: file: /apps/Linux64/aw/maya2014/scripts/others/unifiedRenderGlobalsWindow.mel line 1074: setParent: Object 'unifiedRenderGlobalsWindow' not found. //
is still encountered, even after the file is reopened. It may differs accordingly to scene file
Upvotes: 0
Reputation: 2620
Note: See the "Update" section below in this answer to find the full solution.
Why don't you just try unlocking and setting the currentRenderer
value using setAttr
itself.
cmds.setAttr("defaultRenderGlobals.currentRenderer", l=False)
cmds.setAttr("defaultRenderGlobals.currentRenderer", "mayaHardware", type="string")
You are getting the error //Error: Object ‘tabForm’ not found.
because the render settings window failed to load, probably because of unregistered mentalRay. So AVOID calling the following until current renderer is changed:
mel.eval('updateCurrentRendererSel("unifiedRenderGlobalsRendererSelOptionMenu");')
mel.eval('loadPreferredRenderGlobalsPreset("mayaHardware");')
Update:
From the updates in the question and the comments below, we come to understand that the problem here is that Maya fails to construct the render settings window's UI properly when it encounters a missing renderer or render settings errors. This leads to parent UI components, like the tabs and frames to not being built. As a result, when the renderer is switched, the render settings UI tries to load the corresponding settings into these tabs but cannot find them and stops.
To work around this, we can just set the render settings we want, delete the render settings window's UI completely and reload it. I wrote a quick function for this. This will fix it.
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")
Caveat: This will not prevent the UI from getting lost again if the faulty renderer is somehow selected again. To prevent that, it is better to unload the renderer's plugin. In any case, if the above method is called again, the window should be fixed.
Hope this was useful.
Upvotes: 3