Python Code changes not reflecting in Maya

Python Code changes not reflecting in Maya

imapepsi
Explorer Explorer
1,901 Views
2 Replies
Message 1 of 3

Python Code changes not reflecting in Maya

imapepsi
Explorer
Explorer

I'm using PyCharm2021 and Maya2022 to write code that builds a model for me. My code is split up into modules with a single directory and one main.py that runs the whole program.

 

But in order for Maya to reflect my changes in any of the code files I have to close and restart Maya. Is there a way to avoid restarting Maya?

 

I've heard there's a function called reload in Python, but I wasn't sure how to use it.

0 Likes
Accepted solutions (2)
1,902 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

When you import a .py file into maya it creates an interpreted .pyc file which it can faster read. In order to overwrite the pyc file you need to use the reload function.

The syntax is rather easy:

import main as main
reload(main)

 Btw, if you ever want to publish your script, I would recommend to give your main module a more unique name. 😉

I hope this helps!

Message 3 of 3

imapepsi
Explorer
Explorer
Accepted solution

Thank you for your help! That makes more sense now. It worked! I also had to include the module that reload is in for Python3.

 

import importlib
importlib.reload(module)