__init__.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. '''
  2. To load stuff that assumes a Blender scene is already loaded
  3. I need to wait for the BLEND file of the template to load and
  4. then add the functions and stuff I want after said file loads.
  5. The use of "bpy.app.handlers" and "persistent" help in this case
  6. for some reason I don't undertand yet >:] (but meh, it works)
  7. References:
  8. https://s-nako.work/2020/09/blender-error-attributeerror-_restrictcontext-object-has-no-attribute-view_layer/
  9. https://web.archive.org/web/20210925181415/https://blenderbrew.com/custom-application-templates-in-blender/
  10. '''
  11. import bpy
  12. from bpy.app.handlers import persistent
  13. #################################################
  14. # define function that sets all the blenxy stuff:
  15. # galaxy unit, custom collada exporter/importer
  16. # custom CSV animation file (for BCK) exporter/importer
  17. @persistent
  18. def set_blenxy_env(dummy): # "dummy" is a variable that is somehow
  19. # passed to set_blenxy_env when called by
  20. # bpy.app.handlers.load_post.append
  21. from . import required_modules # install needed modules for bundled python (awful)
  22. from . import basic_settings # settings blenxy has
  23. from . import collada_superbmd_import # "custom" importer for SuperBMD collada files
  24. from . import collada_superbmd_export # "custom" exporter for SuperBMD collada files
  25. # ~ from . import csv_anim_bck_export # exporter for CSV files for BCK conversion
  26. # ~ from . import csv_anim_bck_import # importer for CSV files from BCK animation
  27. # more scripts can be added here
  28. #############################
  29. # register/unregister stuff
  30. # for set_blenxy_env function
  31. def register():
  32. print("\nWelcome to Blenxy!\n")
  33. print("Setting environment...")
  34. bpy.app.handlers.load_post.append(set_blenxy_env)
  35. def unregister():
  36. print("See you later!")
  37. bpy.app.handlers.load_post.remove(set_blenxy_env)
  38. if __name__ == "__main__":
  39. register()