Hey all,
Found that executing a drag/drop Python file using the onMayaDroppedPythonFile function does not reload the module like it did in 2020. As a result, updating the script and drag/dropping it in the viewport will not run the updated version, but the cached version. I have to remove the module from sys.modules in order for drag/drop to reflect any changes. It'd be great if drag/drop automatically reloaded the module on import again. I saw this in 2022.3 and 2023 (haven't tried 2021).
Repro:
Hi!
The relaod funtion works diffrent in python 3, it needs to be imported using importlib. This could be the problem, could you post the exact code you are using, so I could reproduce the problem and verify what is going wrong?
Hi! Thanks for looking into this 🙂 I've attached an example drag/drop script as a .txt file.
In case it's helpful, I compared executeDroppedPythonFile.py between Maya 2020 and 2022. For Maya 2020, I saw it was using imp.load_module, which reloads the module on import. (C:\Program Files\Autodesk\Maya2020\Python\Lib\site-packages\maya\app\general\executeDroppedPythonFile.py line:66)
Maya 2022 is using importlib.import_module. The Python 3.7 docs mentioned load_module was deprecated since 3.4 and recommended exec_module and create_module. I've never used either of those, so I don't know if that's useful info, but maybe it can help save some time. (C:\Program Files\Autodesk\Maya2022\Python37\Lib\site-packages\maya\app\general\executeDroppedPythonFile.py line: 63)
Amy
Found a workaround for anyone with the same issue. In the drag/drop script, within the def onMayaDroppedPythonFile, I remove the module from sys.modules.
e.g., del sys.modules[<"module name">]
I reproduced this issue easily, and it can be fixed by adding module reload on 64 line in C:\Program Files\Autodesk\Maya2022\Python37\Lib\site-packages\maya\app\general\executeDroppedPythonFile.py line
import importlib
loadedModule = importlib.import_module(theModuleName)
importlib.reload(loadedModule)
# If we successfully loaded the module, call the dropped function.
if loadedModule:
Can't find what you're looking for? Ask the community or share your knowledge.