From 2b442c09e4bd74885aac102288072e2539980435 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Fri, 23 Aug 2024 12:28:48 +0200 Subject: [PATCH] fix install path issues and install by default --- __init__.py | 2 ++ butils.py | 36 +++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/__init__.py b/__init__.py index b3a4c11..74424a0 100644 --- a/__init__.py +++ b/__init__.py @@ -611,6 +611,7 @@ class ABC3D_OT_InstallFont(bpy.types.Operator): install_in_assets: bpy.props.BoolProperty( name="install in assets", description="install the font in the assets directory of the addon", + default=True, ) load_into_memory: bpy.props.BoolProperty(name="load font data into memory", @@ -651,6 +652,7 @@ class ABC3D_OT_InstallFont(bpy.types.Operator): target = os.path.join(preferences.assets_dir, "fonts", filename) print(f"installing {scene.abc3d.font_path} -> {target}") import shutil + os.makedirs(os.path.dirname(target), exist_ok=True) shutil.copyfile(scene.abc3d.font_path, target) # def register_load(target, load=False): # print(f"registering installed fonts") diff --git a/butils.py b/butils.py index 7e4fe10..431bc43 100644 --- a/butils.py +++ b/butils.py @@ -507,27 +507,29 @@ def clear_available_fonts(): def load_installed_fonts(): preferences = getPreferences(bpy.context) font_dir = os.path.join(preferences.assets_dir,"fonts") - for file in os.listdir(font_dir): - if file.endswith(".glb") or file.endswith(".gltf"): - font_path = os.path.join(font_dir, file) - # ShowMessageBox("Loading Font", "INFO", f"loading font from {font_path}") - # print(f"loading font from {font_path}") - # for f in bpy.context.scene.abc3d_data.available_fonts.values(): - # print(f"available font: {f.font_name} {f.face_name}") - register_font_from_filepath(font_path) - load_font_from_filepath(font_path) + if os.path.exists(font_dir): + for file in os.listdir(font_dir): + if file.endswith(".glb") or file.endswith(".gltf"): + font_path = os.path.join(font_dir, file) + # ShowMessageBox("Loading Font", "INFO", f"loading font from {font_path}") + # print(f"loading font from {font_path}") + # for f in bpy.context.scene.abc3d_data.available_fonts.values(): + # print(f"available font: {f.font_name} {f.face_name}") + register_font_from_filepath(font_path) + load_font_from_filepath(font_path) def register_installed_fonts(): preferences = getPreferences(bpy.context) font_dir = os.path.join(preferences.assets_dir,"fonts") - for file in os.listdir(font_dir): - if file.endswith(".glb") or file.endswith(".gltf"): - font_path = os.path.join(font_dir, file) - # ShowMessageBox("Loading Font", "INFO", f"loading font from {font_path}") - # print(f"loading font from {font_path}") - # for f in bpy.context.scene.abc3d_data.available_fonts.values(): - # print(f"available font: {f.font_name} {f.face_name}") - register_font_from_filepath(font_path) + if os.path.exists(font_dir): + for file in os.listdir(font_dir): + if file.endswith(".glb") or file.endswith(".gltf"): + font_path = os.path.join(font_dir, file) + # ShowMessageBox("Loading Font", "INFO", f"loading font from {font_path}") + # print(f"loading font from {font_path}") + # for f in bpy.context.scene.abc3d_data.available_fonts.values(): + # print(f"available font: {f.font_name} {f.face_name}") + register_font_from_filepath(font_path) def ShowMessageBox(title = "Message Box", icon = 'INFO', message=""):