# 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 # 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!\n") # 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()