work
save startup blend for animation tab & whatnot
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import getpass
|
||||
import logging
|
||||
import os
|
||||
@@ -38,6 +40,7 @@ BLENDERKIT_OAUTH_LANDING_URL = f"{global_vars.SERVER}/oauth-landing"
|
||||
BLENDERKIT_PLANS_URL = f"{global_vars.SERVER}/plans/pricing"
|
||||
BLENDERKIT_REPORT_URL = f"{global_vars.SERVER}/usage_report"
|
||||
BLENDERKIT_USER_ASSETS_URL = f"{global_vars.SERVER}/my-assets"
|
||||
BLENDERKIT_ASSETS_EDIT_URL = f"{global_vars.SERVER}/asset-edit"
|
||||
BLENDERKIT_MANUAL_URL = "https://youtu.be/0P8ZjfbUjeA"
|
||||
BLENDERKIT_MODEL_UPLOAD_INSTRUCTIONS_URL = f"{global_vars.SERVER}/docs/upload/"
|
||||
BLENDERKIT_PRINTABLE_UPLOAD_INSTRUCTIONS_URL = (
|
||||
@@ -54,6 +57,18 @@ BLENDERKIT_LOGIN_URL = f"{global_vars.SERVER}/accounts/login"
|
||||
BLENDERKIT_SIGNUP_URL = f"{global_vars.SERVER}/accounts/register"
|
||||
|
||||
WINDOWS_PATH_LIMIT = 250
|
||||
ASSET_LIBRARY_NAME = "BlenderKit"
|
||||
|
||||
|
||||
def _normalize_path(path_value: str | None) -> str:
|
||||
"""Return an absolute, normalized path for comparisons; blank string if invalid."""
|
||||
if not path_value:
|
||||
return ""
|
||||
try:
|
||||
resolved = bpy.path.abspath(path_value)
|
||||
except Exception:
|
||||
resolved = path_value
|
||||
return os.path.normpath(os.path.abspath(resolved))
|
||||
|
||||
|
||||
def cleanup_old_directories():
|
||||
@@ -63,7 +78,7 @@ def cleanup_old_directories():
|
||||
try:
|
||||
shutil.rmtree(orig_temp)
|
||||
except Exception as e:
|
||||
bk_logger.error(f"could not delete old temp directory: {e}")
|
||||
bk_logger.error("could not delete old temp directory: %s", e)
|
||||
|
||||
|
||||
def find_in_local(text=""):
|
||||
@@ -134,11 +149,11 @@ def get_temp_dir(subdir=None):
|
||||
cleanup_old_directories()
|
||||
except Exception as e:
|
||||
reports.add_report("Cache directory not found. Resetting Cache directory path.")
|
||||
bk_logger.warning(f"due to exception: {e}")
|
||||
bk_logger.warning("due to exception: %s", e)
|
||||
|
||||
p = default_global_dict()
|
||||
if p == user_preferences.global_dir:
|
||||
message = "Global dir was already default, plese set a global directory in addon preferences to a dir where you have write permissions."
|
||||
message = "Global dir was already default, please set a global directory in addon preferences to a dir where you have write permissions."
|
||||
reports.add_report(message)
|
||||
return None
|
||||
user_preferences.global_dir = p
|
||||
@@ -158,6 +173,7 @@ def get_download_dirs(asset_type):
|
||||
"nodegroup": "nodegroups",
|
||||
"printable": "printables",
|
||||
"addon": "addons",
|
||||
"author": "authors",
|
||||
}
|
||||
|
||||
dirs = []
|
||||
@@ -196,6 +212,84 @@ def get_download_dirs(asset_type):
|
||||
return dirs
|
||||
|
||||
|
||||
def ensure_asset_library_path(
|
||||
global_dir: str | None = None, previous_global_dir: str | None = None
|
||||
):
|
||||
"""Ensure Blender's asset library list contains the BlenderKit library path.
|
||||
|
||||
- Creates the library entry when missing.
|
||||
- Updates an existing entry if the global directory changes.
|
||||
- Reuses a library that already points to the target path even if the name differs.
|
||||
"""
|
||||
if bpy.app.background:
|
||||
return
|
||||
|
||||
filepaths = getattr(bpy.context.preferences, "filepaths", None)
|
||||
asset_libraries = getattr(filepaths, "asset_libraries", None) if filepaths else None
|
||||
if asset_libraries is None:
|
||||
return
|
||||
|
||||
target_path = _normalize_path(
|
||||
global_dir
|
||||
or bpy.context.preferences.addons[__package__].preferences.global_dir # type: ignore
|
||||
)
|
||||
if not target_path:
|
||||
return
|
||||
|
||||
os.makedirs(target_path, exist_ok=True)
|
||||
|
||||
previous_path = _normalize_path(previous_global_dir) if previous_global_dir else ""
|
||||
if previous_path:
|
||||
for lib in asset_libraries:
|
||||
if _normalize_path(lib.path) == previous_path:
|
||||
lib.path = target_path
|
||||
|
||||
existing = (
|
||||
asset_libraries.get(ASSET_LIBRARY_NAME)
|
||||
if hasattr(asset_libraries, "get")
|
||||
else None
|
||||
)
|
||||
if existing is not None:
|
||||
if _normalize_path(existing.path) != target_path:
|
||||
existing.path = target_path
|
||||
return existing
|
||||
|
||||
for lib in asset_libraries:
|
||||
if _normalize_path(lib.path) == target_path:
|
||||
try:
|
||||
lib.name = ASSET_LIBRARY_NAME
|
||||
except Exception:
|
||||
pass
|
||||
return lib
|
||||
|
||||
if hasattr(asset_libraries, "new"):
|
||||
asset_libraries.new(name=ASSET_LIBRARY_NAME, directory=target_path)
|
||||
else:
|
||||
try:
|
||||
bpy.ops.preferences.asset_library_add(directory=target_path)
|
||||
# Operator names the library after the directory basename, rename it.
|
||||
for lib in asset_libraries:
|
||||
if (
|
||||
_normalize_path(lib.path) == target_path
|
||||
and lib.name != ASSET_LIBRARY_NAME
|
||||
):
|
||||
lib.name = ASSET_LIBRARY_NAME
|
||||
break
|
||||
except Exception as e:
|
||||
logging.getLogger(__name__).warning(
|
||||
"Failed to add asset library: %s. "
|
||||
"Please add it manually in Preferences > File Paths",
|
||||
e,
|
||||
)
|
||||
return None
|
||||
|
||||
return (
|
||||
asset_libraries.get(ASSET_LIBRARY_NAME)
|
||||
if hasattr(asset_libraries, "get")
|
||||
else None
|
||||
)
|
||||
|
||||
|
||||
def slugify(input: str) -> str:
|
||||
"""
|
||||
Slugify converts a string to a URL-friendly slug.
|
||||
@@ -423,10 +517,10 @@ def delete_asset_debug(asset_data):
|
||||
continue
|
||||
try:
|
||||
shutil.rmtree(asset_dir)
|
||||
bk_logger.info(f"deleted {asset_dir}")
|
||||
bk_logger.info("deleted asset dir: %s", asset_dir)
|
||||
except Exception as err:
|
||||
e = sys.exc_info()[0]
|
||||
bk_logger.error(f"{e} - {err}")
|
||||
bk_logger.error("%s - %s", e, err)
|
||||
|
||||
|
||||
def get_clean_filepath():
|
||||
|
||||
Reference in New Issue
Block a user