Hello, if I have a .xml theme living under 1 level from the main folder hierarchy (relative to 1 sub level) how can I use an addon to install, activate it and register as an addon?
I found this:
https://docs.blender.org/api/current/bpy.types.Theme.html
But if I am reading well it’s talking about all the elements, but not the .xml file itself.
I’d like to include this in a custom template to launch from _init.py
Please help.
Thanks.
Here’s my operator that I use. I was not able to get it to auto-install as soon as the addon is activated. Instead, I have an “install theme” button in my addon’s preferences to call the below operator. Maybe it’ll give you some hints.
Basically I copy my .xml theme from my addon directory into the theme directory manually (odd, I know). Then I invoke blender’s own operator to switch to this theme. If you find a better way I’d be interested in knowing as well.
class DCONFIG_OT_install_theme(bpy.types.Operator):
bl_idname = "dconfig.install_theme"
bl_label = "DC Install Theme"
bl_description = "Installs custom dconfig theme"
bl_options = {'REGISTER'}
def execute(self, context):
script_path = bpy.utils.user_resource('SCRIPTS')
source_path = os.path.join(script_path, "addons", "dconfig", "dconfig.xml")
target_path = os.path.join(script_path, "presets", "interface_theme")
self.makedir(target_path)
filepath = shutil.copy(source_path, target_path)
bpy.ops.script.execute_preset(filepath=filepath, menu_idname="USERPREF_MT_interface_theme_presets")
return {'FINISHED'}
def makedir(self, target):
if not os.path.exists(target):
os.makedirs(target)
Thanks, this would be a great starting point.