Question about multiple script add-on

Got a question about writing an add-on that uses multiple scripts. I have 3 scripts, 1st one is init.py which contains the add-on dict definition and it either imports or reloads the second script depending upon this bit of code:

if "bpy" in locals():
    import imp
    imp.reload(CityPanel)
    
    print("reloaded CityPanel")
else:
    from . import CityPanel

    print("imported CityPanel")

Now the 2nd script - CityPanel.py imports a 3rd script and works just fine, however the 2nd script just imports the 3rd, doesn’t check to see if it should be reloaded, or imported, as the init.py file does.

So I’m wondering why the 1st script, init.py needs to check for reload or import of the 2nd script, but the 2nd script doesn’t need to check for this condition, and works just fine with import statement only.

Hope I described that clear enough…
Randy

Hi RR…

Here is a snippet from the MocapMadness monster i’m creating

init.py in folder MocapMadness in addons



if "bpy" in locals():
    import imp
    imp.reload(config)
    imp.reload(bvhimport)
    imp.reload(nla)
    imp.reload(space3d)
    imp.reload(graph)
    imp.reload(utils)
    print("RELOADING**********************************")
else:
    print("IMPORTING**********************************")
    from . import config
    from . import bvhimport
    from . import nla
    from . import space3d
    from . import graph
    from . import utils


def register():
    #create a settings variable here
    #config.settings = config.LoadSettings(__path__[0])
    config.data = config.FetchMocapMadness()
    print("register")
    bvhimport.register()
    nla.register()
    space3d.register()
    graph.register()

Then if i want to import any of these i use… for instance in nla.py


import MocapMadness.config as mocapmadness

from MocapMadness.utils import AddHipLocator

Heya batFINGER, thanks for the help, but this is what I am wondering… in my simple example from another thread that you helped with, my init.py looks like this:

if "bpy" in locals():
    import imp
    imp.reload(CityPanel)
    
    print("reloaded CityPanel")
else:
    from . import CityPanel

    print("imported CityPanel")

import bpy



##### REGISTER #####

def register():
    pass


def unregister():
    pass

my ‘CityPanel.py’ first few lines look like this:

### part of a multi-script add-on example/test


import bpy
from . import Rebuild

 
class CityPanel(bpy.types.Panel):
    bl_label = "City Destoyer"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"

So my 2nd script just imports the third script. As you’ve explained, the reload or import in init.py is needed if the user f8 to reload scripts. But if the scripts are reloaded, why doesn’t the second script need to check if it should reload or import the 3rd script? The check to import or reload only exists in the init.py of every multiple script add-on I’ve looked at, so I’m wondering why it’s needed in that script, but not any others…

Randy