__init__.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #######################################################
  18. @persistent
  19. def set_blenxy_env(dummy): # "dummy" is a variable that is somehow
  20. # passed to set_blenxy_env when called by
  21. # bpy.app.handlers.load_post.append
  22. from . import blenxy_settings_stuff # settings blenxy has
  23. from . import collada_bmd_bdl_export # custom exporter for DAE files
  24. from . import collada_bmd_bdl_import # custom importer for DAE 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. #############################
  32. def register():
  33. print("\nWelcome to Blenxy!\n")
  34. print("Setting Blenxy Environment...\n")
  35. bpy.app.handlers.load_post.append(set_blenxy_env)
  36. def unregister():
  37. print("\nSee you later!\n")
  38. bpy.app.handlers.load_post.remove(set_blenxy_env)
  39. if __name__ == "__main__":
  40. register()