summaryrefslogtreecommitdiff
path: root/__init__.py
blob: d20580affc7caba043835c317886d052f0ebf8d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# references
# https://s-nako.work/2020/09/blender-error-attributeerror-_restrictcontext-object-has-no-attribute-view_layer/
# https://web.archive.org/web/20210925181415/https://blenderbrew.com/custom-application-templates-in-blender/

# blenxy module
import importlib, bpy, sys

# import the submmodules needed
# all submodules have a register/unregister function
# register function is to be executed on blenxy's load
# name can be anything but I want to keep the same nomenclature
# the dummy variable passed to the register funcs is needed
# since it is passed when being assigned to the load_post list
# (seems to be None always)
from . import required_modules        # install needed modules for the bundled python
from . import basic_settings          # user settings blenxy has
from . import collada_superbmd_import # custom importer for SuperBMD collada files
from . import collada_superbmd_export # custom exporter for SuperBMD collada files
from . import obj_kcl_export          # custom exporter for OBJ files (collision) 
from . import obj_neokclcreate_import # custom importer for OBJ files (collision, NeoKCLCreate)
from . import bck_import              # custom importer for SMG BCK files
from . import bck_export              # custom exporter for SMG BCK files

# global variables
blenxy_modules = [required_modules,
                  basic_settings,
                  collada_superbmd_import,
                  collada_superbmd_export,
                  obj_kcl_export,
                  obj_neokclcreate_import,
                  bck_import,
                  bck_export]

# function used to refresh blenxy's used modules 
# so that they can be updated without closing blender
@bpy.app.handlers.persistent
def unload_blenxy_stuff(dummy):
  
  # execute the unregister functions from each module
  # these functions won't die if the stuff to unregister isn't there
  for mod in blenxy_modules:
    mod.unregister()
  # reload the modules in case they were modified (dev stuff)
  for mod in blenxy_modules:
    importlib.reload(mod)

# register function that blender will call when the template is loaded
def register():
  
  # print the welcome
  print("\nWelcome to Blenxy!")  
  print("Running on Blender: %s\n" % (bpy.app.version.__str__()))
  
  # add this function to load_post first
  bpy.app.handlers.load_post.append(unload_blenxy_stuff)
  # add the register functions to load_post (old_blenxy_modules)
  for mod in blenxy_modules:
    bpy.app.handlers.load_post.append(mod.register)
  
# unregister function that blender will call when a new template is loaded
def unregister():
  
  # print the goodbye
  print("\nLeaving Blenxy!\n")
  # remove the stuff added to the load_post list
  bpy.app.handlers.load_post.remove(unload_blenxy_stuff)
  for mod in blenxy_modules:
    for func in bpy.app.handlers.load_post:
      if (mod.__name__ in func.__module__):
        bpy.app.handlers.load_post.remove(func)
        break
    
  # execute module's unregister functions
  for mod in blenxy_modules:
    mod.unregister()