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.
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…