Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
An exception is raised if a module was loaded during scene load, and something later attempts to load the module again in the future. For example, if a scene requires stereoCamera, and you then open the Create > Cameras menu, the menu will loadModule -qt 1 "stereoCamera.mll" each time it's opened. Each time will raise an exception:
// Error: file: C:/Program Files/Autodesk/Maya2022/scripts/startup/ModCreateMenu.mel line 1041: (kInvalidParameter): No element at given index
Traceback (most recent call last):
File "C:\Users\glenn\AppData\Roaming\Python\Python37\site-packages\pymel\core_init_.py", line 213, in _pluginLoaded
api.MEventMessage.removeCallback(_pluginData[pluginName]['callbackId'])
RuntimeError: (kInvalidParameter): No element at given index //
// Warning: file: C:/Program Files/Autodesk/Maya2022/scripts/startup/ModCreateMenu.mel line 1041: Python callback failed //
This happens in 2020 and 2022. In 2020 it only happened if loadPlugin's -qt (quiet) argument was 0. In 2022 it happens even if it's true, which is why the Create > Cameras menu is triggering it.
This fixes two parts:
In 2020, the arguments were [pluginPath, pluginFilename].
In 2022, the arguments are [pluginPath, pluginName, pluginFilename], with the extra pluginName (name without extension) in between.
In both versions, pluginFilename is "" if the plugin was already loaded (it wasn't actually just loaded), and loadPlugin was called with -qt 1. The new pluginName argument doesn't do this. This is why this only happened in 2020 with -qt 0 (with -qt 1 then the "if not pluginName" check would short-circuit), and why it always happens in 2022 (pluginName is never empty).
This does mean that loadPlugin -qt 0 will still re-process the plugin load unnecessarily and -qt 1 won't. This could probably be avoided by stopping if _pluginData[pluginName] already exists, but I haven't done that here.
(This callback change seems to be undocumented, I'll file a bug. It also feels like a bug that the pluginName argument changes depending on the -qt flag in the first place...)
Tested in Maya 2020 and 2022.