Compare commits
10 Commits
b027aa063c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dee7c5e6de | ||
|
|
faaf4c8879 | ||
|
|
439682ae65 | ||
|
|
840ccb6ae5 | ||
|
|
0c815967d2 | ||
|
|
226591b085 | ||
|
|
856926869f | ||
|
|
327f9b9c58 | ||
|
|
8de9709022 | ||
|
|
0cbba36311 |
File diff suppressed because it is too large
Load Diff
12
__init__.py
12
__init__.py
@@ -11,18 +11,6 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
bl_info = {
|
|
||||||
"name": "Dynamic Link Manager",
|
|
||||||
"author": "Nathan Lindsay",
|
|
||||||
"version": (0, 0, 1),
|
|
||||||
"blender": (4, 5, 0),
|
|
||||||
"location": "View3D > Sidebar > Dynamic Link Manager",
|
|
||||||
"description": "Replace linked assets and characters with ease",
|
|
||||||
"warning": "",
|
|
||||||
"doc_url": "",
|
|
||||||
"category": "Import-Export",
|
|
||||||
}
|
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from bpy.props import StringProperty, BoolProperty, EnumProperty
|
from bpy.props import StringProperty, BoolProperty, EnumProperty
|
||||||
from bpy.types import Panel, Operator, PropertyGroup
|
from bpy.types import Panel, Operator, PropertyGroup
|
||||||
|
|||||||
@@ -1,73 +1,16 @@
|
|||||||
schema_version = "1.0.0"
|
schema_version = "1.0.0"
|
||||||
|
|
||||||
# Example of manifest file for a Blender extension
|
|
||||||
# Change the values according to your extension
|
|
||||||
id = "dynamiclinkmanager"
|
id = "dynamiclinkmanager"
|
||||||
version = "0.0.1"
|
|
||||||
name = "Dynamic Link Manager"
|
name = "Dynamic Link Manager"
|
||||||
tagline = "Replace linked assets and characters with ease"
|
tagline = "Relink characters and library blends with ease"
|
||||||
maintainer = "Nathan Lindsay"
|
version = "0.0.1"
|
||||||
# Supported types: "add-on", "theme"
|
|
||||||
type = "add-on"
|
type = "add-on"
|
||||||
|
|
||||||
# Optional link to documentation, support, source files, etc
|
# Optional: Semantic Versioning
|
||||||
# website = "https://extensions.blender.org/add-ons/my-example-package/"
|
maintainer = "Nathan Lindsay <nathanlindsay9@gmail.com>"
|
||||||
|
license = ["GPL-3.0-or-later"]
|
||||||
|
blender_version_min = "4.5.0"
|
||||||
|
|
||||||
# Optional list defined by Blender and server, see:
|
website = "http://10.1.10.3:30008/Nathan/Dynamic-Link-Manager"
|
||||||
# https://docs.blender.org/manual/en/dev/advanced/extensions/tags.html
|
|
||||||
tags = ["3D View", "Import-Export"]
|
|
||||||
|
|
||||||
blender_version_min = "4.2.0"
|
tags = ["3D View"]
|
||||||
# # Optional: Blender version that the extension does not support, earlier versions are supported.
|
|
||||||
# # This can be omitted and defined later on the extensions platform if an issue is found.
|
|
||||||
# blender_version_max = "5.1.0"
|
|
||||||
|
|
||||||
# License conforming to https://spdx.org/licenses/ (use "SPDX: prefix)
|
|
||||||
# https://docs.blender.org/manual/en/dev/advanced/extensions/licenses.html
|
|
||||||
license = [
|
|
||||||
"SPDX:GPL-2.0-or-later",
|
|
||||||
]
|
|
||||||
# Optional: required by some licenses.
|
|
||||||
# copyright = [
|
|
||||||
# "2002-2024 Developer Name",
|
|
||||||
# "1998 Company Name",
|
|
||||||
# ]
|
|
||||||
|
|
||||||
# Optional list of supported platforms. If omitted, the extension will be available in all operating systems.
|
|
||||||
# platforms = ["windows-x64", "macos-arm64", "linux-x64"]
|
|
||||||
# Other supported platforms: "windows-arm64", "macos-x64"
|
|
||||||
|
|
||||||
# Optional: bundle 3rd party Python modules.
|
|
||||||
# https://docs.blender.org/manual/en/dev/advanced/extensions/python_wheels.html
|
|
||||||
# wheels = [
|
|
||||||
# "./wheels/hexdump-3.3-py3-none-any.whl",
|
|
||||||
# "./wheels/jsmin-3.0.1-py3-none-any.whl",
|
|
||||||
# ]
|
|
||||||
|
|
||||||
# Optional: add-ons can list which resources they will require:
|
|
||||||
# * files (for access of any filesystem operations)
|
|
||||||
# * network (for internet access)
|
|
||||||
# * clipboard (to read and/or write the system clipboard)
|
|
||||||
# * camera (to capture photos and videos)
|
|
||||||
# * microphone (to capture audio)
|
|
||||||
#
|
|
||||||
# If using network, remember to also check `bpy.app.online_access`
|
|
||||||
# https://docs.blender.org/manual/en/dev/advanced/extensions/addons.html#internet-access
|
|
||||||
#
|
|
||||||
# For each permission it is important to also specify the reason why it is required.
|
|
||||||
# Keep this a single short sentence without a period (.) at the end.
|
|
||||||
# For longer explanations use the documentation or detail page.
|
|
||||||
#
|
|
||||||
# [permissions]
|
|
||||||
# network = "Need to sync motion-capture data to server"
|
|
||||||
# files = "Import/export FBX from/to disk"
|
|
||||||
# clipboard = "Copy and paste bone transforms"
|
|
||||||
|
|
||||||
# Optional: build settings.
|
|
||||||
# https://docs.blender.org/manual/en/dev/advanced/extensions/command_line_arguments.html#command-line-args-extension-build
|
|
||||||
# [build]
|
|
||||||
# paths_exclude_pattern = [
|
|
||||||
# "__pycache__/",
|
|
||||||
# "/.git/",
|
|
||||||
# "/*.zip",
|
|
||||||
# ]
|
|
||||||
543
operators.py
543
operators.py
@@ -80,27 +80,24 @@ class DLM_OT_replace_linked_asset(Operator):
|
|||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
class DLM_OT_scan_linked_assets(Operator):
|
class DLM_OT_scan_linked_assets(Operator):
|
||||||
"""Scan scene for all linked assets"""
|
"""Scan scene for directly linked libraries and their status"""
|
||||||
bl_idname = "dlm.scan_linked_assets"
|
bl_idname = "dlm.scan_linked_assets"
|
||||||
bl_label = "Scan Linked Assets"
|
bl_label = "Scan Linked Libraries"
|
||||||
|
bl_options = {'REGISTER'}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
# Clear previous results
|
# Clear previous results
|
||||||
context.scene.dynamic_link_manager.linked_libraries.clear()
|
context.scene.dynamic_link_manager.linked_libraries.clear()
|
||||||
|
|
||||||
# Dictionary to store library info with hierarchy
|
|
||||||
library_info = {}
|
|
||||||
|
|
||||||
# Function to check if file exists
|
# Function to check if file exists
|
||||||
def is_file_missing(filepath):
|
def is_file_missing(filepath):
|
||||||
if not filepath:
|
if not filepath:
|
||||||
return True
|
return True
|
||||||
# Convert relative paths to absolute
|
try:
|
||||||
if filepath.startswith('//'):
|
abs_path = bpy.path.abspath(filepath)
|
||||||
# This is a relative path, we can't easily check if it exists
|
except Exception:
|
||||||
# So we'll assume it's missing if it's relative
|
abs_path = filepath
|
||||||
return True
|
return not os.path.isfile(abs_path)
|
||||||
return not os.path.exists(filepath)
|
|
||||||
|
|
||||||
# Function to get library name from path
|
# Function to get library name from path
|
||||||
def get_library_name(filepath):
|
def get_library_name(filepath):
|
||||||
@@ -108,85 +105,144 @@ class DLM_OT_scan_linked_assets(Operator):
|
|||||||
return "Unknown"
|
return "Unknown"
|
||||||
return os.path.basename(filepath)
|
return os.path.basename(filepath)
|
||||||
|
|
||||||
# Function to detect indirect links by parsing .blend files safely
|
# Helper: naive scan of a .blend file to find referenced library paths
|
||||||
def get_indirect_libraries(filepath):
|
def scan_blend_for_missing_indirects(blend_path: str) -> bool:
|
||||||
"""Get libraries that are linked from within a .blend file"""
|
"""Return True if the .blend likely references at least one missing
|
||||||
# This function is no longer used with the new approach
|
library (.blend) path. This uses a conservative byte-string scan that
|
||||||
# Indirect links are now detected when attempting to relink
|
never loads data into Blender and is thus context-free and safe.
|
||||||
return set()
|
|
||||||
|
Strategy: look for substrings ending in .blend inside the file bytes
|
||||||
# Scan all data collections for linked items
|
and expand left/right to the nearest NUL byte or line break to
|
||||||
all_libraries = set()
|
reconstruct a plausible filesystem path. If any such path does not
|
||||||
library_info = {} # Store additional info about each library
|
exist on disk, we consider it an indirect missing dependency.
|
||||||
|
"""
|
||||||
# Check bpy.data.objects
|
try:
|
||||||
for obj in bpy.data.objects:
|
if not blend_path or not os.path.exists(blend_path):
|
||||||
if hasattr(obj, 'library') and obj.library:
|
return False
|
||||||
all_libraries.add(obj.library.filepath)
|
with open(blend_path, 'rb') as f:
|
||||||
if obj.data and hasattr(obj.data, 'library') and obj.data.library:
|
data = f.read()
|
||||||
all_libraries.add(obj.data.library.filepath)
|
except Exception:
|
||||||
|
return False
|
||||||
# Check bpy.data.armatures specifically
|
|
||||||
for armature in bpy.data.armatures:
|
import re
|
||||||
if hasattr(armature, 'library') and armature.library:
|
base_dir = os.path.dirname(blend_path)
|
||||||
all_libraries.add(armature.library.filepath)
|
# Consider absolute Windows paths and Blender // relative paths
|
||||||
|
patterns = [
|
||||||
# Check bpy.data.meshes
|
rb"[A-Za-z]:[\\/][^\r\n\0]*?\.blend",
|
||||||
for mesh in bpy.data.meshes:
|
rb"\\\\[^\r\n\0]*?\.blend",
|
||||||
if hasattr(mesh, 'library') and mesh.library:
|
rb"//[^\r\n\0]*?\.blend",
|
||||||
all_libraries.add(mesh.library.filepath)
|
]
|
||||||
|
for pat in patterns:
|
||||||
# Check bpy.data.materials
|
for m in re.finditer(pat, data):
|
||||||
for material in bpy.data.materials:
|
try:
|
||||||
if hasattr(material, 'library') and material.library:
|
s = m.group(0).decode('utf-8', errors='ignore').strip().strip('"\'')
|
||||||
all_libraries.add(material.library.filepath)
|
if s.startswith('//'):
|
||||||
|
rel = s[2:].replace('/', os.sep).replace('\\', os.sep)
|
||||||
# Check bpy.data.images
|
candidate = os.path.normpath(os.path.join(base_dir, rel))
|
||||||
for image in bpy.data.images:
|
else:
|
||||||
if hasattr(image, 'library') and image.library:
|
candidate = s
|
||||||
all_libraries.add(image.library.filepath)
|
if not os.path.isfile(candidate):
|
||||||
|
return True
|
||||||
# Check bpy.data.textures
|
except Exception:
|
||||||
for texture in bpy.data.textures:
|
continue
|
||||||
if hasattr(texture, 'library') and texture.library:
|
return False
|
||||||
all_libraries.add(texture.library.filepath)
|
|
||||||
|
# Reload all libraries up front so Blender populates parent links
|
||||||
# Check bpy.data.node_groups
|
for lib in bpy.data.libraries:
|
||||||
for node_group in bpy.data.node_groups:
|
try:
|
||||||
if hasattr(node_group, 'library') and node_group.library:
|
if lib.filepath:
|
||||||
all_libraries.add(node_group.library.filepath)
|
lib.reload()
|
||||||
|
except Exception:
|
||||||
# Analyze each library for indirect links
|
pass
|
||||||
for filepath in all_libraries:
|
|
||||||
if filepath:
|
# Use Blender's library graph: direct libraries have no parent; indirect
|
||||||
# Initialize with no indirect missing (will be updated during relink attempts)
|
# libraries have parent != None. We display only direct libraries.
|
||||||
library_info[filepath] = {
|
direct_libs = set()
|
||||||
'indirect_libraries': set(),
|
for lib in bpy.data.libraries:
|
||||||
'missing_indirect_count': 0,
|
try:
|
||||||
'has_indirect_missing': False
|
if lib.parent is None and lib.filepath:
|
||||||
}
|
direct_libs.add(lib.filepath)
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Only show directly used libraries in the main list
|
||||||
|
all_libraries = set(direct_libs)
|
||||||
|
|
||||||
# Store results in scene properties
|
# Store results in scene properties
|
||||||
context.scene.dynamic_link_manager.linked_assets_count = len(all_libraries)
|
context.scene.dynamic_link_manager.linked_assets_count = len(all_libraries)
|
||||||
|
|
||||||
# Create library items for the UI
|
# Build set of direct-parent libraries that have at least one missing
|
||||||
for filepath in sorted(all_libraries):
|
# indirect child, using the library.parent chain.
|
||||||
if filepath:
|
missing_indirect_libs = set()
|
||||||
lib_item = context.scene.dynamic_link_manager.linked_libraries.add()
|
for lib in bpy.data.libraries:
|
||||||
lib_item.filepath = filepath
|
try:
|
||||||
lib_item.name = get_library_name(filepath)
|
if lib.parent is not None and lib.filepath:
|
||||||
lib_item.is_missing = is_file_missing(filepath)
|
try:
|
||||||
|
abs_child = bpy.path.abspath(lib.filepath)
|
||||||
# Set indirect link information
|
except Exception:
|
||||||
if filepath in library_info:
|
abs_child = lib.filepath
|
||||||
info = library_info[filepath]
|
if not os.path.isfile(abs_child):
|
||||||
lib_item.has_indirect_missing = info['has_indirect_missing']
|
# climb up to the root direct parent
|
||||||
lib_item.indirect_missing_count = info['missing_indirect_count']
|
root = lib.parent
|
||||||
else:
|
while getattr(root, 'parent', None) is not None:
|
||||||
lib_item.has_indirect_missing = False
|
root = root.parent
|
||||||
lib_item.indirect_missing_count = 0
|
if root and root.filepath:
|
||||||
|
missing_indirect_libs.add(root.filepath)
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Additionally, mark any direct library as INDIRECT if any of its
|
||||||
|
# linked ID users are flagged as missing by Blender (e.g., the source
|
||||||
|
# .blend no longer contains the datablock). This catches cases where
|
||||||
|
# the library file exists but its contents are missing.
|
||||||
|
missing_ids_by_library = set()
|
||||||
|
def check_missing_on(ids):
|
||||||
|
for idb in ids:
|
||||||
|
try:
|
||||||
|
lib = getattr(idb, 'library', None)
|
||||||
|
if lib and lib.filepath and getattr(idb, 'is_library_missing', False):
|
||||||
|
missing_ids_by_library.add(lib.filepath)
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
|
check_missing_on(bpy.data.objects)
|
||||||
|
check_missing_on(bpy.data.meshes)
|
||||||
|
check_missing_on(bpy.data.armatures)
|
||||||
|
check_missing_on(bpy.data.materials)
|
||||||
|
check_missing_on(bpy.data.node_groups)
|
||||||
|
check_missing_on(bpy.data.images)
|
||||||
|
check_missing_on(bpy.data.texts)
|
||||||
|
check_missing_on(bpy.data.collections)
|
||||||
|
check_missing_on(bpy.data.cameras)
|
||||||
|
check_missing_on(bpy.data.lights)
|
||||||
|
|
||||||
|
# Create library items for the UI based on definitive indirect set
|
||||||
|
library_items = []
|
||||||
|
for filepath in sorted(all_libraries):
|
||||||
|
if not filepath:
|
||||||
|
continue
|
||||||
|
lib_item = context.scene.dynamic_link_manager.linked_libraries.add()
|
||||||
|
lib_item.filepath = filepath
|
||||||
|
lib_item.name = get_library_name(filepath)
|
||||||
|
lib_item.is_missing = is_file_missing(filepath)
|
||||||
|
|
||||||
|
# INDIRECT if it has a missing indirect child OR any linked IDs are missing
|
||||||
|
lib_item.is_indirect = (filepath in missing_indirect_libs) or (filepath in missing_ids_by_library)
|
||||||
|
|
||||||
|
# Store for sorting
|
||||||
|
library_items.append((lib_item, filepath))
|
||||||
|
|
||||||
|
# Sort libraries: missing first, then by name
|
||||||
|
library_items.sort(key=lambda x: (not x[0].is_missing, get_library_name(x[1]).lower()))
|
||||||
|
|
||||||
|
# Clear and re-add in sorted order
|
||||||
|
context.scene.dynamic_link_manager.linked_libraries.clear()
|
||||||
|
for lib_item, filepath in library_items:
|
||||||
|
new_item = context.scene.dynamic_link_manager.linked_libraries.add()
|
||||||
|
new_item.filepath = filepath
|
||||||
|
new_item.name = get_library_name(filepath) # Use the function directly
|
||||||
|
new_item.is_missing = lib_item.is_missing
|
||||||
|
new_item.is_indirect = lib_item.is_indirect
|
||||||
|
|
||||||
# Show detailed info
|
# Show detailed info
|
||||||
self.report({'INFO'}, f"Found {len(all_libraries)} unique linked library files")
|
self.report({'INFO'}, f"Found {len(all_libraries)} unique linked library files")
|
||||||
@@ -196,10 +252,10 @@ class DLM_OT_scan_linked_assets(Operator):
|
|||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class DLM_OT_fmt_style_find(Operator):
|
class DLM_OT_find_libraries_in_folders(Operator):
|
||||||
"""Find missing libraries in search folders using FMT-style approach"""
|
"""Find missing libraries in search folders and attempt to relocate them"""
|
||||||
bl_idname = "dlm.fmt_style_find"
|
bl_idname = "dlm.find_libraries_in_folders"
|
||||||
bl_label = "FMT-Style Find"
|
bl_label = "Find Libraries in Folders"
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
@@ -214,24 +270,70 @@ class DLM_OT_fmt_style_find(Operator):
|
|||||||
self.report({'INFO'}, "No missing libraries to find")
|
self.report({'INFO'}, "No missing libraries to find")
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
self.report({'INFO'}, f"FMT-style search for {len(missing_libs)} missing libraries...")
|
self.report({'INFO'}, f"Searching for {len(missing_libs)} missing libraries in search paths...")
|
||||||
|
|
||||||
# FMT-style directory scanning (exact copy of FMT logic)
|
# Recursive directory scanning (searches all subfolders)
|
||||||
files_dir_list = []
|
files_dir_list = []
|
||||||
|
total_dirs_scanned = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for search_path in prefs.preferences.search_paths:
|
for search_path in prefs.preferences.search_paths:
|
||||||
if search_path.path:
|
if search_path.path:
|
||||||
for dirpath, dirnames, filenames in os.walk(bpy.path.abspath(search_path.path)):
|
# Handle both relative and absolute paths
|
||||||
|
if search_path.path.startswith("//"):
|
||||||
|
# Relative path - convert to absolute
|
||||||
|
abs_path = bpy.path.abspath(search_path.path)
|
||||||
|
else:
|
||||||
|
# Absolute path - use as is
|
||||||
|
abs_path = search_path.path
|
||||||
|
|
||||||
|
self.report({'INFO'}, f"Scanning search path: {abs_path}")
|
||||||
|
|
||||||
|
# Check if path exists and is accessible
|
||||||
|
if not os.path.exists(abs_path):
|
||||||
|
self.report({'WARNING'}, f"Search path does not exist or is not accessible: {abs_path}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not os.path.isdir(abs_path):
|
||||||
|
self.report({'WARNING'}, f"Search path is not a directory: {abs_path}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Use os.walk to recursively scan all subdirectories
|
||||||
|
for dirpath, dirnames, filenames in os.walk(abs_path):
|
||||||
files_dir_list.append([dirpath, filenames])
|
files_dir_list.append([dirpath, filenames])
|
||||||
except FileNotFoundError:
|
total_dirs_scanned += 1
|
||||||
self.report({'ERROR'}, f"Error - Bad file path in search paths")
|
|
||||||
|
# Debug: Show what we're finding
|
||||||
|
if len(filenames) > 0:
|
||||||
|
blend_files = [f for f in filenames if f.endswith('.blend')]
|
||||||
|
if blend_files:
|
||||||
|
self.report({'INFO'}, f" Found {len(blend_files)} .blend files in: {dirpath}")
|
||||||
|
|
||||||
|
# Limit to prevent excessive scanning (safety measure)
|
||||||
|
if total_dirs_scanned > 1000:
|
||||||
|
self.report({'WARNING'}, "Reached scan limit of 1000 directories. Some subfolders may not be scanned.")
|
||||||
|
break
|
||||||
|
|
||||||
|
self.report({'INFO'}, f"Scanned {total_dirs_scanned} directories from search path: {abs_path}")
|
||||||
|
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
self.report({'ERROR'}, f"Error - Bad file path in search paths: {e}")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
except Exception as e:
|
||||||
|
self.report({'ERROR'}, f"Error scanning search paths: {e}")
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
# FMT-style library finding
|
self.report({'INFO'}, f"Total directories scanned: {total_dirs_scanned}")
|
||||||
|
|
||||||
|
# Phase 1: Library finding with recursive search
|
||||||
|
found_libraries = {} # Dictionary to store filename -> full path mapping
|
||||||
found_count = 0
|
found_count = 0
|
||||||
|
|
||||||
|
self.report({'INFO'}, "=== PHASE 1: SEARCHING FOR LIBRARIES ===")
|
||||||
|
|
||||||
for lib_item in missing_libs:
|
for lib_item in missing_libs:
|
||||||
lib_filename = os.path.basename(lib_item.filepath)
|
lib_filename = os.path.basename(lib_item.filepath)
|
||||||
|
self.report({'INFO'}, f"Looking for: {lib_filename}")
|
||||||
|
|
||||||
for dir_info in files_dir_list:
|
for dir_info in files_dir_list:
|
||||||
dirpath, filenames = dir_info
|
dirpath, filenames = dir_info
|
||||||
@@ -239,18 +341,52 @@ class DLM_OT_fmt_style_find(Operator):
|
|||||||
# Exact filename match
|
# Exact filename match
|
||||||
if lib_filename in filenames:
|
if lib_filename in filenames:
|
||||||
new_path = os.path.join(dirpath, lib_filename)
|
new_path = os.path.join(dirpath, lib_filename)
|
||||||
self.report({'INFO'}, f"Found {lib_filename} at: {new_path}")
|
found_libraries[lib_filename] = new_path
|
||||||
|
self.report({'INFO'}, f"✓ Found {lib_filename} at: {new_path}")
|
||||||
found_count += 1
|
found_count += 1
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# FMT-style reporting
|
self.report({'INFO'}, f"=== SEARCH COMPLETE: Found {found_count} out of {len(missing_libs)} missing libraries ===")
|
||||||
|
|
||||||
|
# Phase 2: Relinking found libraries
|
||||||
if found_count > 0:
|
if found_count > 0:
|
||||||
self.report({'INFO'}, f"FMT-style search complete: Found {found_count} libraries")
|
self.report({'INFO'}, "=== PHASE 2: RELINKING LIBRARIES ===")
|
||||||
|
|
||||||
|
# Manual, deterministic relink of exact filename matches.
|
||||||
|
relinked_count = 0
|
||||||
|
for lib in bpy.data.libraries:
|
||||||
|
try:
|
||||||
|
if not lib.filepath:
|
||||||
|
continue
|
||||||
|
lib_filename = os.path.basename(lib.filepath)
|
||||||
|
if lib_filename in found_libraries:
|
||||||
|
new_path = found_libraries[lib_filename]
|
||||||
|
# Only update if currently missing and different
|
||||||
|
current_abs = bpy.path.abspath(lib.filepath)
|
||||||
|
if (not os.path.isfile(current_abs)) or (current_abs != new_path):
|
||||||
|
lib.filepath = new_path
|
||||||
|
try:
|
||||||
|
lib.reload()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
relinked_count += 1
|
||||||
|
self.report({'INFO'}, f"Relinked {lib_filename} -> {new_path}")
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if relinked_count == 0:
|
||||||
|
self.report({'WARNING'}, "No libraries were relinked; ensure filenames match exactly in search paths.")
|
||||||
|
else:
|
||||||
|
self.report({'INFO'}, f"✓ Manually relinked {relinked_count} libraries")
|
||||||
else:
|
else:
|
||||||
self.report({'WARNING'}, "FMT-style search: No libraries found in search paths")
|
self.report({'WARNING'}, "No libraries found in search paths - nothing to relink")
|
||||||
|
|
||||||
|
# Trigger a rescan so UI reflects current status immediately
|
||||||
|
try:
|
||||||
|
bpy.ops.dlm.scan_linked_assets()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
self.report({'INFO'}, "=== OPERATION COMPLETE ===")
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
@@ -352,7 +488,7 @@ class DLM_OT_attempt_relink(Operator):
|
|||||||
self.report({'ERROR'}, f"Error - Bad file path in search paths")
|
self.report({'ERROR'}, f"Error - Bad file path in search paths")
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
# Try to find and relink each missing library (FMT-style)
|
# Try to find and relink each missing library
|
||||||
relinked_count = 0
|
relinked_count = 0
|
||||||
indirect_errors = []
|
indirect_errors = []
|
||||||
|
|
||||||
@@ -400,70 +536,7 @@ class DLM_OT_attempt_relink(Operator):
|
|||||||
self.report({'INFO'}, f"Relink attempt complete. Relinked: {relinked_count}, Indirect: {len(indirect_errors)}")
|
self.report({'INFO'}, f"Relink attempt complete. Relinked: {relinked_count}, Indirect: {len(indirect_errors)}")
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class DLM_OT_find_in_folders(Operator):
|
|
||||||
"""Find missing libraries in search folders and subfolders"""
|
|
||||||
bl_idname = "dlm.find_in_folders"
|
|
||||||
bl_label = "Find in Folders"
|
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
prefs = context.preferences.addons.get(__package__)
|
|
||||||
if not prefs or not prefs.preferences.search_paths:
|
|
||||||
self.report({'ERROR'}, "No search paths configured. Add search paths in addon preferences.")
|
|
||||||
return {'CANCELLED'}
|
|
||||||
|
|
||||||
# Get missing libraries
|
|
||||||
missing_libs = [lib for lib in context.scene.dynamic_link_manager.linked_libraries if lib.is_missing]
|
|
||||||
if not missing_libs:
|
|
||||||
self.report({'INFO'}, "No missing libraries to find")
|
|
||||||
return {'FINISHED'}
|
|
||||||
|
|
||||||
self.report({'INFO'}, f"Searching for {len(missing_libs)} missing libraries...")
|
|
||||||
|
|
||||||
# FMT-style directory scanning
|
|
||||||
files_dir_list = []
|
|
||||||
try:
|
|
||||||
for search_path in prefs.preferences.search_paths:
|
|
||||||
if search_path.path:
|
|
||||||
for dirpath, dirnames, filenames in os.walk(bpy.path.abspath(search_path.path)):
|
|
||||||
files_dir_list.append([dirpath, filenames])
|
|
||||||
except FileNotFoundError:
|
|
||||||
self.report({'ERROR'}, f"Error - Bad file path in search paths")
|
|
||||||
return {'CANCELLED'}
|
|
||||||
|
|
||||||
# Try to find each missing library (FMT-style)
|
|
||||||
found_count = 0
|
|
||||||
|
|
||||||
for lib_item in missing_libs:
|
|
||||||
lib_filename = os.path.basename(lib_item.filepath)
|
|
||||||
found = False
|
|
||||||
|
|
||||||
# Search through all directories
|
|
||||||
for dir_info in files_dir_list:
|
|
||||||
dirpath, filenames = dir_info
|
|
||||||
|
|
||||||
# Look for exact filename match
|
|
||||||
if lib_filename in filenames:
|
|
||||||
new_path = os.path.join(dirpath, lib_filename)
|
|
||||||
self.report({'INFO'}, f"Found {lib_filename} at: {new_path}")
|
|
||||||
found_count += 1
|
|
||||||
found = True
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if found:
|
|
||||||
break
|
|
||||||
|
|
||||||
if not found:
|
|
||||||
self.report({'WARNING'}, f"Could not find {lib_filename} in search paths")
|
|
||||||
|
|
||||||
if found_count > 0:
|
|
||||||
self.report({'INFO'}, f"Found {found_count} libraries in search paths")
|
|
||||||
else:
|
|
||||||
self.report({'WARNING'}, "No libraries found in search paths")
|
|
||||||
|
|
||||||
return {'FINISHED'}
|
|
||||||
|
|
||||||
class DLM_OT_browse_search_path(Operator):
|
class DLM_OT_browse_search_path(Operator):
|
||||||
"""Browse for a search path directory"""
|
"""Browse for a search path directory"""
|
||||||
@@ -502,6 +575,130 @@ class DLM_OT_browse_search_path(Operator):
|
|||||||
context.window_manager.fileselect_add(self)
|
context.window_manager.fileselect_add(self)
|
||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DLM_OT_reload_libraries(Operator):
|
||||||
|
"""Reload all libraries using Blender's built-in reload operation"""
|
||||||
|
bl_idname = "dlm.reload_libraries"
|
||||||
|
bl_label = "Reload Libraries"
|
||||||
|
bl_options = {'REGISTER'}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
try:
|
||||||
|
# Try the outliner operation first
|
||||||
|
bpy.ops.outliner.lib_operation(type='RELOAD')
|
||||||
|
self.report({'INFO'}, "Library reload operation completed")
|
||||||
|
except Exception as e:
|
||||||
|
# Fallback: manually reload libraries
|
||||||
|
try:
|
||||||
|
for library in bpy.data.libraries:
|
||||||
|
if library.filepath and os.path.exists(bpy.path.abspath(library.filepath)):
|
||||||
|
library.reload()
|
||||||
|
self.report({'INFO'}, "Libraries reloaded manually")
|
||||||
|
except Exception as e2:
|
||||||
|
self.report({'ERROR'}, f"Failed to reload libraries: {e2}")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class DLM_OT_make_paths_relative(Operator):
|
||||||
|
"""Make all file paths in the scene relative"""
|
||||||
|
bl_idname = "dlm.make_paths_relative"
|
||||||
|
bl_label = "Make Paths Relative"
|
||||||
|
bl_options = {'REGISTER'}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
try:
|
||||||
|
# Use Blender's built-in operator to make paths relative
|
||||||
|
bpy.ops.file.make_paths_relative()
|
||||||
|
self.report({'INFO'}, "All file paths made relative")
|
||||||
|
except Exception as e:
|
||||||
|
self.report({'ERROR'}, f"Failed to make paths relative: {e}")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class DLM_OT_make_paths_absolute(Operator):
|
||||||
|
"""Make all file paths in the scene absolute"""
|
||||||
|
bl_idname = "dlm.make_paths_absolute"
|
||||||
|
bl_label = "Make Paths Absolute"
|
||||||
|
bl_options = {'REGISTER'}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
try:
|
||||||
|
# Use Blender's built-in operator to make paths absolute
|
||||||
|
bpy.ops.file.make_paths_absolute()
|
||||||
|
self.report({'INFO'}, "All file paths made absolute")
|
||||||
|
except Exception as e:
|
||||||
|
self.report({'ERROR'}, f"Failed to make paths absolute: {e}")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class DLM_OT_relocate_single_library(Operator):
|
||||||
|
"""Relocate a single library by choosing a new .blend and reloading it (context-free)"""
|
||||||
|
bl_idname = "dlm.relocate_single_library"
|
||||||
|
bl_label = "Relocate Library"
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
|
# The library we want to relocate (current path as stored on the item)
|
||||||
|
target_filepath: StringProperty(
|
||||||
|
name="Current Library Path",
|
||||||
|
description="Current path of the library to relocate",
|
||||||
|
default=""
|
||||||
|
)
|
||||||
|
|
||||||
|
# New file chosen by the user via file selector
|
||||||
|
filepath: StringProperty(
|
||||||
|
name="New Library File",
|
||||||
|
description="Choose the new .blend file for this library",
|
||||||
|
subtype='FILE_PATH',
|
||||||
|
default=""
|
||||||
|
)
|
||||||
|
|
||||||
|
def _find_library_by_path(self, path_to_match: str):
|
||||||
|
abs_match = bpy.path.abspath(path_to_match) if path_to_match else ""
|
||||||
|
for lib in bpy.data.libraries:
|
||||||
|
try:
|
||||||
|
if bpy.path.abspath(lib.filepath) == abs_match:
|
||||||
|
return lib
|
||||||
|
except Exception:
|
||||||
|
# In case abspath fails for odd paths
|
||||||
|
if lib.filepath == path_to_match:
|
||||||
|
return lib
|
||||||
|
return None
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
if not self.target_filepath:
|
||||||
|
self.report({'ERROR'}, "No target library specified")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
if not self.filepath:
|
||||||
|
self.report({'ERROR'}, "No new file selected")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
library = self._find_library_by_path(self.target_filepath)
|
||||||
|
if not library:
|
||||||
|
self.report({'ERROR'}, "Could not resolve the selected library in bpy.data.libraries")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Assign the new path and reload the library datablocks
|
||||||
|
library.filepath = self.filepath
|
||||||
|
library.reload()
|
||||||
|
self.report({'INFO'}, f"Relocated to: {self.filepath}")
|
||||||
|
except Exception as e:
|
||||||
|
self.report({'ERROR'}, f"Failed to relocate: {e}")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
# Pre-populate the selector with the current path when possible
|
||||||
|
if self.target_filepath:
|
||||||
|
try:
|
||||||
|
self.filepath = bpy.path.abspath(self.target_filepath)
|
||||||
|
except Exception:
|
||||||
|
self.filepath = self.target_filepath
|
||||||
|
context.window_manager.fileselect_add(self)
|
||||||
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(DLM_OT_replace_linked_asset)
|
bpy.utils.register_class(DLM_OT_replace_linked_asset)
|
||||||
bpy.utils.register_class(DLM_OT_scan_linked_assets)
|
bpy.utils.register_class(DLM_OT_scan_linked_assets)
|
||||||
@@ -510,12 +707,14 @@ def register():
|
|||||||
bpy.utils.register_class(DLM_OT_remove_search_path)
|
bpy.utils.register_class(DLM_OT_remove_search_path)
|
||||||
bpy.utils.register_class(DLM_OT_browse_search_path)
|
bpy.utils.register_class(DLM_OT_browse_search_path)
|
||||||
bpy.utils.register_class(DLM_OT_attempt_relink)
|
bpy.utils.register_class(DLM_OT_attempt_relink)
|
||||||
bpy.utils.register_class(DLM_OT_find_in_folders)
|
bpy.utils.register_class(DLM_OT_find_libraries_in_folders)
|
||||||
bpy.utils.register_class(DLM_OT_fmt_style_find)
|
bpy.utils.register_class(DLM_OT_reload_libraries)
|
||||||
|
bpy.utils.register_class(DLM_OT_make_paths_relative)
|
||||||
|
bpy.utils.register_class(DLM_OT_make_paths_absolute)
|
||||||
|
bpy.utils.register_class(DLM_OT_relocate_single_library)
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(DLM_OT_fmt_style_find)
|
bpy.utils.unregister_class(DLM_OT_find_libraries_in_folders)
|
||||||
bpy.utils.unregister_class(DLM_OT_find_in_folders)
|
|
||||||
bpy.utils.unregister_class(DLM_OT_attempt_relink)
|
bpy.utils.unregister_class(DLM_OT_attempt_relink)
|
||||||
bpy.utils.unregister_class(DLM_OT_browse_search_path)
|
bpy.utils.unregister_class(DLM_OT_browse_search_path)
|
||||||
bpy.utils.unregister_class(DLM_OT_remove_search_path)
|
bpy.utils.unregister_class(DLM_OT_remove_search_path)
|
||||||
@@ -523,3 +722,7 @@ def unregister():
|
|||||||
bpy.utils.unregister_class(DLM_OT_open_linked_file)
|
bpy.utils.unregister_class(DLM_OT_open_linked_file)
|
||||||
bpy.utils.unregister_class(DLM_OT_scan_linked_assets)
|
bpy.utils.unregister_class(DLM_OT_scan_linked_assets)
|
||||||
bpy.utils.unregister_class(DLM_OT_replace_linked_asset)
|
bpy.utils.unregister_class(DLM_OT_replace_linked_asset)
|
||||||
|
bpy.utils.unregister_class(DLM_OT_reload_libraries)
|
||||||
|
bpy.utils.unregister_class(DLM_OT_make_paths_relative)
|
||||||
|
bpy.utils.unregister_class(DLM_OT_make_paths_absolute)
|
||||||
|
bpy.utils.unregister_class(DLM_OT_relocate_single_library)
|
||||||
|
|||||||
223
ui.py
223
ui.py
@@ -15,13 +15,13 @@ class LinkedDatablockItem(PropertyGroup):
|
|||||||
name: StringProperty(name="Name", description="Name of the linked datablock")
|
name: StringProperty(name="Name", description="Name of the linked datablock")
|
||||||
type: StringProperty(name="Type", description="Type of the linked datablock")
|
type: StringProperty(name="Type", description="Type of the linked datablock")
|
||||||
|
|
||||||
# FMT-style UIList for linked libraries
|
# UIList for linked libraries
|
||||||
class DYNAMICLINK_UL_library_list(UIList):
|
class DLM_UL_library_list(UIList):
|
||||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||||
custom_icon = 'FILE_BLEND'
|
custom_icon = 'FILE_BLEND'
|
||||||
|
|
||||||
if self.layout_type in {'DEFAULT', 'COMPACT'}:
|
if self.layout_type in {'DEFAULT', 'COMPACT'}:
|
||||||
# Library name and status (FMT-style layout)
|
# Library name and status
|
||||||
layout.scale_x = 0.4
|
layout.scale_x = 0.4
|
||||||
layout.label(text=item.name)
|
layout.label(text=item.name)
|
||||||
|
|
||||||
@@ -29,17 +29,30 @@ class DYNAMICLINK_UL_library_list(UIList):
|
|||||||
layout.scale_x = 0.3
|
layout.scale_x = 0.3
|
||||||
if item.is_missing:
|
if item.is_missing:
|
||||||
layout.label(text="MISSING", icon='ERROR')
|
layout.label(text="MISSING", icon='ERROR')
|
||||||
elif item.has_indirect_missing:
|
elif item.is_indirect:
|
||||||
layout.label(text="INDIRECT", icon='ERROR')
|
layout.label(text="INDIRECT", icon='INFO')
|
||||||
else:
|
else:
|
||||||
layout.label(text="OK", icon='FILE_BLEND')
|
layout.label(text="OK", icon='FILE_BLEND')
|
||||||
|
|
||||||
# File path (FMT-style truncated)
|
# File path (abbreviated)
|
||||||
layout.scale_x = 0.3
|
layout.scale_x = 0.3
|
||||||
path_text = item.filepath
|
path_text = item.filepath
|
||||||
if len(path_text) > 30:
|
if path_text.startswith("\\\\"):
|
||||||
path_text = "..." + path_text[-27:]
|
# Network path: show server name
|
||||||
layout.label(text=path_text, icon='FILE_FOLDER')
|
parts = path_text.split("\\")
|
||||||
|
if len(parts) >= 3:
|
||||||
|
short_path = f"\\\\{parts[2]}\\"
|
||||||
|
else:
|
||||||
|
short_path = "\\\\ (network)"
|
||||||
|
elif len(path_text) >= 2 and path_text[1] == ':':
|
||||||
|
# Drive path: show drive letter
|
||||||
|
short_path = f"{path_text[:2]}\\"
|
||||||
|
elif path_text.startswith("//"):
|
||||||
|
# Relative path
|
||||||
|
short_path = "// (relative)"
|
||||||
|
else:
|
||||||
|
short_path = path_text[:15] + "..." if len(path_text) > 15 else path_text
|
||||||
|
layout.label(text=short_path, icon='FILE_FOLDER')
|
||||||
|
|
||||||
elif self.layout_type in {'GRID'}:
|
elif self.layout_type in {'GRID'}:
|
||||||
layout.alignment = 'CENTER'
|
layout.alignment = 'CENTER'
|
||||||
@@ -50,8 +63,7 @@ class LinkedLibraryItem(PropertyGroup):
|
|||||||
filepath: StringProperty(name="File Path", description="Path to the linked .blend file")
|
filepath: StringProperty(name="File Path", description="Path to the linked .blend file")
|
||||||
name: StringProperty(name="Name", description="Name of the linked .blend file")
|
name: StringProperty(name="Name", description="Name of the linked .blend file")
|
||||||
is_missing: BoolProperty(name="Missing", description="True if the linked file is not found")
|
is_missing: BoolProperty(name="Missing", description="True if the linked file is not found")
|
||||||
has_indirect_missing: BoolProperty(name="Has Indirect Missing", description="True if an indirectly linked blend is missing")
|
is_indirect: BoolProperty(name="Is Indirect", description="True if this is an indirectly linked library")
|
||||||
indirect_missing_count: IntProperty(name="Indirect Missing Count", description="Number of indirectly linked blends that are missing")
|
|
||||||
is_expanded: BoolProperty(name="Expanded", description="Whether this library item is expanded in the UI", default=True)
|
is_expanded: BoolProperty(name="Expanded", description="Whether this library item is expanded in the UI", default=True)
|
||||||
linked_datablocks: CollectionProperty(type=LinkedDatablockItem, name="Linked Datablocks")
|
linked_datablocks: CollectionProperty(type=LinkedDatablockItem, name="Linked Datablocks")
|
||||||
|
|
||||||
@@ -93,7 +105,7 @@ class DynamicLinkManagerPreferences(AddonPreferences):
|
|||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
|
|
||||||
# Search paths section (FMT-style)
|
# Search paths section
|
||||||
box = layout.box()
|
box = layout.box()
|
||||||
box.label(text="Default Search Paths for Missing Libraries")
|
box.label(text="Default Search Paths for Missing Libraries")
|
||||||
|
|
||||||
@@ -102,35 +114,81 @@ class DynamicLinkManagerPreferences(AddonPreferences):
|
|||||||
row.alignment = 'RIGHT'
|
row.alignment = 'RIGHT'
|
||||||
row.operator("dlm.add_search_path", text="Add search path", icon='ADD')
|
row.operator("dlm.add_search_path", text="Add search path", icon='ADD')
|
||||||
|
|
||||||
# List search paths (FMT-style)
|
# List search paths
|
||||||
for i, path_item in enumerate(self.search_paths):
|
for i, path_item in enumerate(self.search_paths):
|
||||||
row = box.row()
|
row = box.row()
|
||||||
row.prop(path_item, "path", text=f"Search path {i+1}")
|
row.prop(path_item, "path", text=f"Search path {i+1}")
|
||||||
# Folder icon for browsing (FMT-style)
|
# Folder icon for browsing
|
||||||
row.operator("dlm.browse_search_path", text="", icon='FILE_FOLDER').index = i
|
row.operator("dlm.browse_search_path", text="", icon='FILE_FOLDER').index = i
|
||||||
# Remove button (FMT-style)
|
# Remove button
|
||||||
row.operator("dlm.remove_search_path", text="", icon='REMOVE').index = i
|
row.operator("dlm.remove_search_path", text="", icon='REMOVE').index = i
|
||||||
|
|
||||||
class DYNAMICLINK_PT_main_panel(Panel):
|
class DLM_PT_main_panel(Panel):
|
||||||
bl_space_type = 'VIEW_3D'
|
bl_space_type = 'VIEW_3D'
|
||||||
bl_region_type = 'UI'
|
bl_region_type = 'UI'
|
||||||
bl_category = 'Dynamic Link Manager'
|
bl_category = 'Dynamic Link Manager'
|
||||||
bl_label = "Asset Replacement"
|
bl_label = "Dynamic Link Manager"
|
||||||
|
|
||||||
|
def get_short_path(self, filepath):
|
||||||
|
"""Extract a short, readable path from a full filepath"""
|
||||||
|
if not filepath:
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
|
# Handle relative paths
|
||||||
|
if filepath.startswith("//"):
|
||||||
|
return "// (relative)"
|
||||||
|
|
||||||
|
# Handle Windows network paths
|
||||||
|
if filepath.startswith("\\\\"):
|
||||||
|
# Extract server name (e.g., \\NAS\ or \\NEXUS\)
|
||||||
|
parts = filepath.split("\\")
|
||||||
|
if len(parts) >= 3:
|
||||||
|
return f"\\\\{parts[2]}\\"
|
||||||
|
return "\\\\ (network)"
|
||||||
|
|
||||||
|
# Handle Windows drive paths
|
||||||
|
if len(filepath) >= 2 and filepath[1] == ':':
|
||||||
|
return f"{filepath[:2]}\\"
|
||||||
|
|
||||||
|
# Handle Unix-style paths
|
||||||
|
if filepath.startswith("/"):
|
||||||
|
parts = filepath.split("/")
|
||||||
|
if len(parts) >= 2:
|
||||||
|
return f"/{parts[1]}/"
|
||||||
|
return "/ (root)"
|
||||||
|
|
||||||
|
# Fallback
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
|
def draw_header(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
layout.operator("preferences.addon_show", text="", icon='PREFERENCES').module = __package__
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
props = context.scene.dynamic_link_manager
|
props = context.scene.dynamic_link_manager
|
||||||
|
|
||||||
# Main scan section (FMT-style)
|
# Path management buttons
|
||||||
|
row = layout.row()
|
||||||
|
row.operator("dlm.make_paths_relative", text="Make Paths Relative", icon='FILE_PARENT')
|
||||||
|
row.operator("dlm.make_paths_absolute", text="Make Paths Absolute", icon='FILE_FOLDER')
|
||||||
|
|
||||||
|
# Main scan section
|
||||||
box = layout.box()
|
box = layout.box()
|
||||||
box.label(text="Linked Libraries Analysis")
|
box.label(text="Linked Libraries Analysis")
|
||||||
row = box.row()
|
row = box.row()
|
||||||
row.operator("dlm.scan_linked_assets", text="Scan Linked Assets", icon='FILE_REFRESH')
|
row.operator("dlm.scan_linked_assets", text="Scan Linked Assets", icon='FILE_REFRESH')
|
||||||
row.label(text=f"({props.linked_assets_count} libraries)")
|
|
||||||
|
# Show total count and missing count
|
||||||
|
missing_count = sum(1 for lib in props.linked_libraries if lib.is_missing)
|
||||||
|
if missing_count > 0:
|
||||||
|
row.label(text=f"({props.linked_assets_count} libraries, {missing_count} missing)", icon='ERROR')
|
||||||
|
else:
|
||||||
|
row.label(text=f"({props.linked_assets_count} libraries)")
|
||||||
|
|
||||||
# Show more detailed info if we have results
|
# Show more detailed info if we have results
|
||||||
if props.linked_assets_count > 0:
|
if props.linked_assets_count > 0:
|
||||||
# Linked Libraries section with single dropdown (FMT-style)
|
# Linked Libraries section with single dropdown
|
||||||
row = box.row(align=True)
|
row = box.row(align=True)
|
||||||
|
|
||||||
# Dropdown arrow for the entire section
|
# Dropdown arrow for the entire section
|
||||||
@@ -143,105 +201,82 @@ class DYNAMICLINK_PT_main_panel(Panel):
|
|||||||
|
|
||||||
# Only show library details if section is expanded
|
# Only show library details if section is expanded
|
||||||
if props.linked_libraries_expanded:
|
if props.linked_libraries_expanded:
|
||||||
# FMT-style compact list view
|
# Compact list view
|
||||||
row = box.row()
|
row = box.row()
|
||||||
row.template_list("DYNAMICLINK_UL_library_list", "", props, "linked_libraries", props, "linked_libraries_index")
|
row.template_list("DLM_UL_library_list", "", props, "linked_libraries", props, "linked_libraries_index")
|
||||||
|
|
||||||
# Action buttons below the list (FMT-style)
|
# Action buttons below the list
|
||||||
row = box.row()
|
row = box.row()
|
||||||
row.scale_x = 0.3
|
row.operator("dlm.reload_libraries", text="Reload Libraries", icon='FILE_REFRESH')
|
||||||
if props.linked_libraries and 0 <= props.linked_libraries_index < len(props.linked_libraries):
|
|
||||||
selected_lib = props.linked_libraries[props.linked_libraries_index]
|
|
||||||
open_op = row.operator("dlm.open_linked_file", text="Open Selected", icon='FILE_BLEND')
|
|
||||||
open_op.filepath = selected_lib.filepath
|
|
||||||
else:
|
|
||||||
row.operator("dlm.open_linked_file", text="Open Selected", icon='FILE_BLEND')
|
|
||||||
row.scale_x = 0.7
|
|
||||||
row.operator("dlm.scan_linked_assets", text="Refresh", icon='FILE_REFRESH')
|
|
||||||
|
|
||||||
# Show details of selected item (FMT-style info display)
|
# Search Paths Management - integrated into Linked Libraries Analysis
|
||||||
if props.linked_libraries and 0 <= props.linked_libraries_index < len(props.linked_libraries):
|
|
||||||
selected_lib = props.linked_libraries[props.linked_libraries_index]
|
|
||||||
info_box = box.box()
|
|
||||||
info_box.label(text=f"Selected: {selected_lib.name}")
|
|
||||||
|
|
||||||
if selected_lib.is_missing:
|
|
||||||
info_box.label(text="Status: MISSING", icon='ERROR')
|
|
||||||
elif selected_lib.has_indirect_missing:
|
|
||||||
info_box.label(text=f"Status: INDIRECT MISSING ({selected_lib.indirect_missing_count} dependencies)", icon='ERROR')
|
|
||||||
else:
|
|
||||||
info_box.label(text="Status: OK", icon='FILE_BLEND')
|
|
||||||
|
|
||||||
info_box.label(text=f"Path: {selected_lib.filepath}", icon='FILE_FOLDER')
|
|
||||||
|
|
||||||
# Search Paths Management (FMT-style) - integrated into Linked Libraries Analysis
|
|
||||||
if props.linked_assets_count > 0:
|
if props.linked_assets_count > 0:
|
||||||
# Get preferences for search paths
|
# Get preferences for search paths
|
||||||
prefs = context.preferences.addons.get(__package__)
|
prefs = context.preferences.addons.get(__package__)
|
||||||
|
|
||||||
# Search paths list (FMT-style) - Each path gets its own row with folder icon
|
# Search paths list - Each path gets its own row with folder icon
|
||||||
if prefs and prefs.preferences.search_paths:
|
if prefs and prefs.preferences.search_paths:
|
||||||
for i, path_item in enumerate(prefs.preferences.search_paths):
|
for i, path_item in enumerate(prefs.preferences.search_paths):
|
||||||
row = box.row()
|
row = box.row()
|
||||||
row.prop(path_item, "path", text=f"Search path {i+1}")
|
row.prop(path_item, "path", text=f"Search path {i+1}")
|
||||||
# Folder icon for browsing (FMT-style)
|
# Folder icon for browsing
|
||||||
row.operator("dlm.browse_search_path", text="", icon='FILE_FOLDER').index = i
|
row.operator("dlm.browse_search_path", text="", icon='FILE_FOLDER').index = i
|
||||||
# Remove button (FMT-style)
|
# Remove button
|
||||||
row.operator("dlm.remove_search_path", text="", icon='REMOVE').index = i
|
row.operator("dlm.remove_search_path", text="", icon='REMOVE').index = i
|
||||||
|
|
||||||
# Add button (FMT-style) - Just the + button, right-justified
|
# Add button - Just the + button, right-justified
|
||||||
row = box.row()
|
row = box.row()
|
||||||
row.alignment = 'RIGHT'
|
row.alignment = 'RIGHT'
|
||||||
row.operator("dlm.add_search_path", text="", icon='ADD')
|
row.operator("dlm.add_search_path", text="Add search path", icon='ADD')
|
||||||
|
|
||||||
# Main action button (FMT-style)
|
# Main action button
|
||||||
missing_count = sum(1 for lib in props.linked_libraries if lib.is_missing)
|
|
||||||
if missing_count > 0:
|
if missing_count > 0:
|
||||||
row = box.row()
|
row = box.row()
|
||||||
row.operator("dlm.fmt_style_find", text="Find libraries in these folders", icon='VIEWZOOM')
|
row.operator("dlm.find_libraries_in_folders", text="Find libraries in these folders", icon='VIEWZOOM')
|
||||||
|
|
||||||
# Asset replacement section (FMT-style)
|
# Show details of selected item at the bottom
|
||||||
box = layout.box()
|
if props.linked_libraries and 0 <= props.linked_libraries_index < len(props.linked_libraries):
|
||||||
box.label(text="Asset Replacement")
|
selected_lib = props.linked_libraries[props.linked_libraries_index]
|
||||||
|
info_box = box.box()
|
||||||
obj = context.active_object
|
|
||||||
if obj:
|
# Make entire box red if library is missing
|
||||||
box.label(text=f"Selected: {obj.name}")
|
if selected_lib.is_missing:
|
||||||
|
info_box.alert = True
|
||||||
# Check if object itself is linked
|
|
||||||
if obj.library:
|
info_box.label(text=f"Selected: {selected_lib.name}")
|
||||||
box.label(text=f"Linked from: {obj.library.filepath}")
|
|
||||||
row = box.row()
|
if selected_lib.is_missing:
|
||||||
row.operator("dlm.replace_linked_asset", text="Replace Asset")
|
row = info_box.row()
|
||||||
# Check if object's data is linked
|
row.label(text="Status: MISSING", icon='ERROR')
|
||||||
elif obj.data and obj.data.library:
|
elif selected_lib.is_indirect:
|
||||||
box.label(text=f"Data linked from: {obj.data.library.filepath}")
|
row = info_box.row()
|
||||||
row = box.row()
|
row.label(text="Status: INDIRECT", icon='INFO')
|
||||||
row.operator("dlm.replace_linked_asset", text="Replace Asset")
|
else:
|
||||||
# Check if it's a linked armature
|
row = info_box.row()
|
||||||
elif obj.type == 'ARMATURE' and obj.data and hasattr(obj.data, 'library') and obj.data.library:
|
row.label(text="Status: OK", icon='FILE_BLEND')
|
||||||
box.label(text=f"Armature linked from: {obj.data.library.filepath}")
|
|
||||||
row = box.row()
|
# Show full path and Open Blend button
|
||||||
row.operator("dlm.replace_linked_asset", text="Replace Asset")
|
row = info_box.row()
|
||||||
else:
|
row.label(text=f"Path: {selected_lib.filepath}", icon='FILE_FOLDER')
|
||||||
box.label(text="Not a linked asset")
|
|
||||||
else:
|
row = info_box.row()
|
||||||
box.label(text="No object selected")
|
row.operator("dlm.open_linked_file", text="Open Blend", icon='FILE_BLEND').filepath = selected_lib.filepath
|
||||||
|
|
||||||
# Settings section (FMT-style)
|
# Relocate (context-free): lets the user pick a new .blend and we reload the library
|
||||||
box = layout.box()
|
row = info_box.row()
|
||||||
box.label(text="Settings")
|
op = row.operator("dlm.relocate_single_library", text="Relocate Library", icon='FILE_FOLDER')
|
||||||
row = box.row()
|
op.target_filepath = selected_lib.filepath
|
||||||
row.prop(props, "selected_asset_path", text="Asset Path")
|
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
bpy.utils.register_class(SearchPathItem)
|
bpy.utils.register_class(SearchPathItem)
|
||||||
bpy.utils.register_class(LinkedDatablockItem)
|
bpy.utils.register_class(LinkedDatablockItem)
|
||||||
bpy.utils.register_class(DYNAMICLINK_UL_library_list)
|
bpy.utils.register_class(DLM_UL_library_list)
|
||||||
bpy.utils.register_class(LinkedLibraryItem)
|
bpy.utils.register_class(LinkedLibraryItem)
|
||||||
bpy.utils.register_class(DynamicLinkManagerProperties)
|
bpy.utils.register_class(DynamicLinkManagerProperties)
|
||||||
bpy.utils.register_class(DynamicLinkManagerPreferences)
|
bpy.utils.register_class(DynamicLinkManagerPreferences)
|
||||||
bpy.utils.register_class(DYNAMICLINK_PT_main_panel)
|
bpy.utils.register_class(DLM_PT_main_panel)
|
||||||
|
|
||||||
# Register properties to scene
|
# Register properties to scene
|
||||||
bpy.types.Scene.dynamic_link_manager = bpy.props.PointerProperty(type=DynamicLinkManagerProperties)
|
bpy.types.Scene.dynamic_link_manager = bpy.props.PointerProperty(type=DynamicLinkManagerProperties)
|
||||||
@@ -250,10 +285,10 @@ def unregister():
|
|||||||
# Unregister properties from scene
|
# Unregister properties from scene
|
||||||
del bpy.types.Scene.dynamic_link_manager
|
del bpy.types.Scene.dynamic_link_manager
|
||||||
|
|
||||||
bpy.utils.unregister_class(DYNAMICLINK_PT_main_panel)
|
bpy.utils.unregister_class(DLM_PT_main_panel)
|
||||||
bpy.utils.unregister_class(DynamicLinkManagerPreferences)
|
bpy.utils.unregister_class(DynamicLinkManagerPreferences)
|
||||||
bpy.utils.unregister_class(DynamicLinkManagerProperties)
|
bpy.utils.unregister_class(DynamicLinkManagerProperties)
|
||||||
bpy.utils.unregister_class(LinkedLibraryItem)
|
bpy.utils.unregister_class(LinkedLibraryItem)
|
||||||
bpy.utils.unregister_class(DYNAMICLINK_UL_library_list)
|
bpy.utils.unregister_class(DLM_UL_library_list)
|
||||||
bpy.utils.unregister_class(LinkedDatablockItem)
|
bpy.utils.unregister_class(LinkedDatablockItem)
|
||||||
bpy.utils.unregister_class(SearchPathItem)
|
bpy.utils.unregister_class(SearchPathItem)
|
||||||
|
|||||||
Reference in New Issue
Block a user