How to reload add-on code

I’m trying to modify an add-on that consists of an init.py file and several class files.
What is the process add-on developers use to reload the add-on after a code change?

1 Like

F3 / Reload Scripts

1 Like

@bareflix did this work? Is there some requirement with the script setup? It’s not working for me…

Seems silly to make a new thread when this is exactly what I want but I’m really struggling to make this work.

I’ve tried to simplify it to the core, here is the code I’ve ended up with

if I change the print message from main.py and reload,the change is not getting printed in the console when I run first FirstOperator from the search menu.

Any help would be appreciated! EDIT Solved below

Well, typically shortly after posting I tried some more things and got it working :laughing:

Removing the else: section and leaving it so “from .main import *” always fires seems to reload the code in main.

I have updated the github with the working code & uploaded here in case it helps anyone else

init.py|attachment (819 Bytes) main.py (540 Bytes)

Here’s an example of how to keep all modules update when you’re developing an addon:

import importlib

if "geo" in locals():
    importlib.reload(geo)
else:
    from . import geo

This imports “geo” module and reloads it if it’s already imported. Do this for all modules that you are modifying while developing.

Doing import * is in my opinion very bad practice that is hard to later fix.

Can you clarify is the “module” the file called geo.py and not the class in that file?

In my example if I do

from . import main

it then wont find the classes in main.py

I have to do

from .main import FirstOperator
from .main import SecondOperator

ah I see! if you do

from . import main

you refrence FirstOperator with

'main.FirstOperator'

Thanks for the advice, I’ll avoid import *