2025-12-01

This commit is contained in:
2026-03-17 14:58:51 -06:00
parent 183e865f8b
commit 4b82b57113
6846 changed files with 954887 additions and 162606 deletions
@@ -0,0 +1,43 @@
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import bpy
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import Panel, Operator, PropertyGroup
# Import local modules
from . import operators
from . import ui
def ensure_default_search_path():
"""Ensure there's always at least one search path"""
prefs = bpy.context.preferences.addons.get(__name__)
if prefs and len(prefs.preferences.search_paths) == 0:
new_path = prefs.preferences.search_paths.add()
new_path.path = "//" # Default to relative path
def register():
operators.register()
ui.register()
# Ensure default search path exists
bpy.app.handlers.load_post.append(ensure_default_search_path)
def unregister():
ui.unregister()
operators.unregister()
# Remove the handler
if ensure_default_search_path in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.remove(ensure_default_search_path)
if __name__ == "__main__":
register()
@@ -0,0 +1,16 @@
schema_version = "1.0.0"
id = "dynamiclinkmanager"
name = "Dynamic Link Manager"
tagline = "Relink characters and library blends with ease"
version = "0.0.1"
type = "add-on"
# Optional: Semantic Versioning
maintainer = "Nathan Lindsay <nathanlindsay9@gmail.com>"
license = ["GPL-3.0-or-later"]
blender_version_min = "4.5.0"
website = "http://10.1.10.3:30008/Nathan/Dynamic-Link-Manager"
tags = ["3D View"]
@@ -0,0 +1,525 @@
import bpy
import os
from bpy.types import Operator
from bpy.props import StringProperty, BoolProperty, EnumProperty, IntProperty
class DLM_OT_replace_linked_asset(Operator):
"""Replace a linked asset with a new file"""
bl_idname = "dlm.replace_linked_asset"
bl_label = "Replace Linked Asset"
bl_options = {'REGISTER', 'UNDO'}
filepath: StringProperty(
name="File Path",
description="Path to the new asset file",
subtype='FILE_PATH'
)
def execute(self, context):
obj = context.active_object
if not obj:
self.report({'ERROR'}, "No object selected")
return {'CANCELLED'}
# Comprehensive debug info
debug_info = f"Object: {obj.name}, Type: {obj.type}"
# Check object library
if hasattr(obj, 'library'):
debug_info += f", Object has library attr: {obj.library is not None}"
if obj.library:
debug_info += f", Object library: {obj.library.filepath}"
# Check object data
if obj.data:
debug_info += f", Has data: {type(obj.data).__name__}, Name: {obj.data.name}"
# Check data library attribute
if hasattr(obj.data, 'library'):
debug_info += f", Data.library exists: {obj.data.library is not None}"
if obj.data.library:
debug_info += f", Data.library.filepath: {obj.data.library.filepath}"
# Check if data is in bpy.data collections
if obj.type == 'ARMATURE' and obj.data.name in bpy.data.armatures:
armature_data = bpy.data.armatures[obj.data.name]
debug_info += f", Found in bpy.data.armatures"
if hasattr(armature_data, 'library'):
debug_info += f", bpy.data library: {armature_data.library is not None}"
if armature_data.library:
debug_info += f", bpy.data library path: {armature_data.library.filepath}"
# Check if data is in bpy.data.objects
if obj.data.name in bpy.data.objects:
debug_info += f", Data also in bpy.data.objects"
# Check if object itself is linked
if hasattr(obj, 'library') and obj.library:
self.report({'INFO'}, f"Object '{obj.name}' is linked from: {obj.library.filepath}")
return {'FINISHED'}
# Check if object's data is linked
if obj.data and hasattr(obj.data, 'library') and obj.data.library:
self.report({'INFO'}, f"Object '{obj.name}' has linked data from: {obj.data.library.filepath}")
return {'FINISHED'}
# Check if armature data is linked through bpy.data system
if obj.type == 'ARMATURE' and obj.data and obj.data.name in bpy.data.armatures:
armature_data = bpy.data.armatures[obj.data.name]
if hasattr(armature_data, 'library') and armature_data.library:
self.report({'INFO'}, f"Armature '{obj.name}' data is linked from: {armature_data.library.filepath}")
return {'FINISHED'}
# If we get here, show debug info
self.report({'WARNING'}, debug_info)
self.report({'ERROR'}, "Selected object is not a linked asset")
return {'CANCELLED'}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
class DLM_OT_scan_linked_assets(Operator):
"""Scan scene for all linked assets"""
bl_idname = "dlm.scan_linked_assets"
bl_label = "Scan Linked Assets"
def execute(self, context):
# Clear previous results
context.scene.dynamic_link_manager.linked_libraries.clear()
# Dictionary to store library info with hierarchy
library_info = {}
# Function to check if file exists
def is_file_missing(filepath):
if not filepath:
return True
# Convert relative paths to absolute
if filepath.startswith('//'):
# This is a relative path, we can't easily check if it exists
# So we'll assume it's missing if it's relative
return True
return not os.path.exists(filepath)
# Function to get library name from path
def get_library_name(filepath):
if not filepath:
return "Unknown"
return os.path.basename(filepath)
# Function to detect indirect links by parsing .blend files safely
def get_indirect_libraries(filepath):
"""Get libraries that are linked from within a .blend file"""
# This function is no longer used with the new approach
# Indirect links are now detected when attempting to relink
return set()
# Scan all data collections for linked items
all_libraries = set()
library_info = {} # Store additional info about each library
# Check bpy.data.objects
for obj in bpy.data.objects:
if hasattr(obj, 'library') and obj.library:
all_libraries.add(obj.library.filepath)
if obj.data and hasattr(obj.data, 'library') and obj.data.library:
all_libraries.add(obj.data.library.filepath)
# Check bpy.data.armatures specifically
for armature in bpy.data.armatures:
if hasattr(armature, 'library') and armature.library:
all_libraries.add(armature.library.filepath)
# Check bpy.data.meshes
for mesh in bpy.data.meshes:
if hasattr(mesh, 'library') and mesh.library:
all_libraries.add(mesh.library.filepath)
# Check bpy.data.materials
for material in bpy.data.materials:
if hasattr(material, 'library') and material.library:
all_libraries.add(material.library.filepath)
# Check bpy.data.images
for image in bpy.data.images:
if hasattr(image, 'library') and image.library:
all_libraries.add(image.library.filepath)
# Check bpy.data.textures
for texture in bpy.data.textures:
if hasattr(texture, 'library') and texture.library:
all_libraries.add(texture.library.filepath)
# Check bpy.data.node_groups
for node_group in bpy.data.node_groups:
if hasattr(node_group, 'library') and node_group.library:
all_libraries.add(node_group.library.filepath)
# Analyze each library for indirect links
for filepath in all_libraries:
if filepath:
# Initialize with no indirect missing (will be updated during relink attempts)
library_info[filepath] = {
'indirect_libraries': set(),
'missing_indirect_count': 0,
'has_indirect_missing': False
}
# Store results in scene properties
context.scene.dynamic_link_manager.linked_assets_count = len(all_libraries)
# Create library items for the UI
for filepath in sorted(all_libraries):
if filepath:
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)
# Set indirect link information
if filepath in library_info:
info = library_info[filepath]
lib_item.has_indirect_missing = info['has_indirect_missing']
lib_item.indirect_missing_count = info['missing_indirect_count']
else:
lib_item.has_indirect_missing = False
lib_item.indirect_missing_count = 0
# Show detailed info
self.report({'INFO'}, f"Found {len(all_libraries)} unique linked library files")
if all_libraries:
for lib in sorted(all_libraries):
self.report({'INFO'}, f"Library: {lib}")
return {'FINISHED'}
class DLM_OT_fmt_style_find(Operator):
"""Find missing libraries in search folders using FMT-style approach"""
bl_idname = "dlm.fmt_style_find"
bl_label = "FMT-Style Find"
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"FMT-style search for {len(missing_libs)} missing libraries...")
# FMT-style directory scanning (exact copy of FMT logic)
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'}
# FMT-style library finding
found_count = 0
for lib_item in missing_libs:
lib_filename = os.path.basename(lib_item.filepath)
for dir_info in files_dir_list:
dirpath, filenames = dir_info
# 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
break
# FMT-style reporting
if found_count > 0:
self.report({'INFO'}, f"FMT-style search complete: Found {found_count} libraries")
else:
self.report({'WARNING'}, "FMT-style search: No libraries found in search paths")
return {'FINISHED'}
def register():
bpy.utils.register_class(DLM_OT_replace_linked_asset)
bpy.utils.register_class(DLM_OT_scan_linked_assets)
class DLM_OT_open_linked_file(Operator):
"""Open the linked file in a new Blender instance"""
bl_idname = "dlm.open_linked_file"
bl_label = "Open Linked File"
bl_options = {'REGISTER'}
filepath: StringProperty(
name="File Path",
description="Path to the linked file",
default=""
)
def execute(self, context):
if not self.filepath:
self.report({'ERROR'}, "No file path specified")
return {'CANCELLED'}
# Try to open the linked file in a new Blender instance
try:
# Use Blender's built-in file browser to open the file
bpy.ops.wm.path_open(filepath=self.filepath)
self.report({'INFO'}, f"Opening linked file: {self.filepath}")
except Exception as e:
self.report({'ERROR'}, f"Failed to open linked file: {e}")
return {'CANCELLED'}
return {'FINISHED'}
class DLM_OT_add_search_path(Operator):
"""Add a new search path for missing libraries"""
bl_idname = "dlm.add_search_path"
bl_label = "Add Search Path"
bl_options = {'REGISTER'}
def execute(self, context):
prefs = context.preferences.addons.get(__package__)
if prefs:
new_path = prefs.preferences.search_paths.add()
new_path.path = "//" # Default to relative path
self.report({'INFO'}, f"Added search path: {new_path.path}")
return {'FINISHED'}
class DLM_OT_remove_search_path(Operator):
"""Remove a search path"""
bl_idname = "dlm.remove_search_path"
bl_label = "Remove Search Path"
bl_options = {'REGISTER'}
index: IntProperty(
name="Index",
description="Index of the search path to remove",
default=0
)
def execute(self, context):
prefs = context.preferences.addons.get(__package__)
if prefs and prefs.preferences.search_paths:
if 0 <= self.index < len(prefs.preferences.search_paths):
prefs.preferences.search_paths.remove(self.index)
self.report({'INFO'}, f"Removed search path at index {self.index}")
else:
self.report({'ERROR'}, f"Invalid index: {self.index}")
return {'FINISHED'}
class DLM_OT_attempt_relink(Operator):
"""Attempt to relink missing libraries using search paths"""
bl_idname = "dlm.attempt_relink"
bl_label = "Attempt Relink"
bl_options = {'REGISTER'}
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 relink")
return {'FINISHED'}
self.report({'INFO'}, f"Attempting to relink {len(missing_libs)} missing libraries...")
# Scan search paths for missing libraries (FMT-inspired approach)
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 and relink each missing library (FMT-style)
relinked_count = 0
indirect_errors = []
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)
try:
# Try to relink using Blender's system
# This will naturally detect indirect links if they exist
bpy.ops.file.find_missing_files()
found = True
relinked_count += 1
break
except Exception as e:
error_msg = str(e)
if "unable to relocate indirectly linked library" in error_msg:
indirect_errors.append(lib_item.filepath)
print(f"Indirect link detected for: {lib_item.filepath}")
else:
print(f"Error relinking {lib_item.filepath}: {e}")
if found:
break
if not found:
print(f"Could not find {lib_filename} in search paths")
# Update the UI to show indirect links
if indirect_errors:
self.report({'WARNING'}, f"Found {len(indirect_errors)} indirectly linked libraries")
# Mark these as having indirect missing
for lib_item in context.scene.dynamic_link_manager.linked_libraries:
if lib_item.filepath in indirect_errors:
lib_item.has_indirect_missing = True
lib_item.indirect_missing_count = 1
self.report({'INFO'}, f"Relink attempt complete. Relinked: {relinked_count}, Indirect: {len(indirect_errors)}")
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):
"""Browse for a search path directory"""
bl_idname = "dlm.browse_search_path"
bl_label = "Browse Search Path"
bl_options = {'REGISTER'}
index: IntProperty(
name="Index",
description="Index of the search path to browse for",
default=0
)
filepath: StringProperty(
name="Search Path",
description="Path to search for missing linked libraries",
subtype='DIR_PATH'
)
def execute(self, context):
prefs = context.preferences.addons.get(__package__)
if prefs and prefs.preferences.search_paths:
if 0 <= self.index < len(prefs.preferences.search_paths):
prefs.preferences.search_paths[self.index].path = self.filepath
self.report({'INFO'}, f"Updated search path {self.index + 1}: {self.filepath}")
else:
self.report({'ERROR'}, f"Invalid index: {self.index}")
return {'FINISHED'}
def invoke(self, context, event):
prefs = context.preferences.addons.get(__package__)
if prefs and prefs.preferences.search_paths:
if 0 <= self.index < len(prefs.preferences.search_paths):
# Set the current path as default
self.filepath = prefs.preferences.search_paths[self.index].path
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def register():
bpy.utils.register_class(DLM_OT_replace_linked_asset)
bpy.utils.register_class(DLM_OT_scan_linked_assets)
bpy.utils.register_class(DLM_OT_open_linked_file)
bpy.utils.register_class(DLM_OT_add_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_attempt_relink)
bpy.utils.register_class(DLM_OT_find_in_folders)
bpy.utils.register_class(DLM_OT_fmt_style_find)
def unregister():
bpy.utils.unregister_class(DLM_OT_fmt_style_find)
bpy.utils.unregister_class(DLM_OT_find_in_folders)
bpy.utils.unregister_class(DLM_OT_attempt_relink)
bpy.utils.unregister_class(DLM_OT_browse_search_path)
bpy.utils.unregister_class(DLM_OT_remove_search_path)
bpy.utils.unregister_class(DLM_OT_add_search_path)
bpy.utils.unregister_class(DLM_OT_open_linked_file)
bpy.utils.unregister_class(DLM_OT_scan_linked_assets)
bpy.utils.unregister_class(DLM_OT_replace_linked_asset)
@@ -0,0 +1,263 @@
import bpy
from bpy.types import Panel, PropertyGroup, AddonPreferences, UIList
from bpy.props import IntProperty, StringProperty, BoolProperty, CollectionProperty
# Properties for search paths
class SearchPathItem(PropertyGroup):
path: StringProperty(
name="Search Path",
description="Path to search for missing linked libraries",
subtype='DIR_PATH'
)
# Properties for individual linked datablocks
class LinkedDatablockItem(PropertyGroup):
name: StringProperty(name="Name", description="Name of the linked datablock")
type: StringProperty(name="Type", description="Type of the linked datablock")
# FMT-style UIList for linked libraries
class DYNAMICLINK_UL_library_list(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
custom_icon = 'FILE_BLEND'
if self.layout_type in {'DEFAULT', 'COMPACT'}:
# Library name and status (FMT-style layout)
layout.scale_x = 0.4
layout.label(text=item.name)
# Status indicator
layout.scale_x = 0.3
if item.is_missing:
layout.label(text="MISSING", icon='ERROR')
elif item.has_indirect_missing:
layout.label(text="INDIRECT", icon='ERROR')
else:
layout.label(text="OK", icon='FILE_BLEND')
# File path (FMT-style truncated)
layout.scale_x = 0.3
path_text = item.filepath
if len(path_text) > 30:
path_text = "..." + path_text[-27:]
layout.label(text=path_text, icon='FILE_FOLDER')
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label(text="", icon=custom_icon)
# Properties for a single linked library file
class LinkedLibraryItem(PropertyGroup):
filepath: StringProperty(name="File Path", description="Path to 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")
has_indirect_missing: BoolProperty(name="Has Indirect Missing", description="True if an indirectly linked blend is missing")
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)
linked_datablocks: CollectionProperty(type=LinkedDatablockItem, name="Linked Datablocks")
class DynamicLinkManagerProperties(PropertyGroup):
linked_libraries: CollectionProperty(type=LinkedLibraryItem, name="Linked Libraries")
linked_libraries_index: IntProperty(
name="Linked Libraries Index",
description="Index of the selected linked library",
default=0
)
linked_assets_count: IntProperty(
name="Linked Assets Count",
description="Number of linked assets found in scene",
default=0
)
linked_libraries_expanded: BoolProperty(
name="Linked Libraries Expanded",
description="Whether the linked libraries section is expanded",
default=True
)
selected_asset_path: StringProperty(
name="Selected Asset Path",
description="Path to the currently selected asset",
default=""
)
# Addon preferences for search paths
class DynamicLinkManagerPreferences(AddonPreferences):
bl_idname = __package__
search_paths: CollectionProperty(
type=SearchPathItem,
name="Search Paths",
description="Paths to search for missing linked libraries"
)
def draw(self, context):
layout = self.layout
# Search paths section (FMT-style)
box = layout.box()
box.label(text="Default Search Paths for Missing Libraries")
# Add button - right-justified
row = box.row()
row.alignment = 'RIGHT'
row.operator("dlm.add_search_path", text="Add search path", icon='ADD')
# List search paths (FMT-style)
for i, path_item in enumerate(self.search_paths):
row = box.row()
row.prop(path_item, "path", text=f"Search path {i+1}")
# Folder icon for browsing (FMT-style)
row.operator("dlm.browse_search_path", text="", icon='FILE_FOLDER').index = i
# Remove button (FMT-style)
row.operator("dlm.remove_search_path", text="", icon='REMOVE').index = i
class DLM_PT_main_panel(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Dynamic Link Manager'
bl_label = "Dynamic Link Manager"
def draw_header(self, context):
layout = self.layout
layout.operator("preferences.addon_show", text="", icon='PREFERENCES').module = __package__
def draw(self, context):
layout = self.layout
props = context.scene.dynamic_link_manager
# Main scan section (FMT-style)
box = layout.box()
box.label(text="Linked Libraries Analysis")
row = box.row()
row.operator("dlm.scan_linked_assets", text="Scan Linked Assets", icon='FILE_REFRESH')
row.label(text=f"({props.linked_assets_count} libraries)")
# Show more detailed info if we have results
if props.linked_assets_count > 0:
# Linked Libraries section with single dropdown (FMT-style)
row = box.row(align=True)
# Dropdown arrow for the entire section
icon = 'DISCLOSURE_TRI_DOWN' if props.linked_libraries_expanded else 'DISCLOSURE_TRI_RIGHT'
row.prop(props, "linked_libraries_expanded", text="", icon=icon, icon_only=True)
# Section header
row.label(text="Linked Libraries:")
row.label(text=f"({props.linked_assets_count} libraries)")
# Only show library details if section is expanded
if props.linked_libraries_expanded:
# FMT-style compact list view
row = box.row()
row.template_list("DYNAMICLINK_UL_library_list", "", props, "linked_libraries", props, "linked_libraries_index")
# Action buttons below the list (FMT-style)
row = box.row()
row.scale_x = 0.3
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)
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:
# Get preferences for search paths
prefs = context.preferences.addons.get(__package__)
# Search paths list (FMT-style) - Each path gets its own row with folder icon
if prefs and prefs.preferences.search_paths:
for i, path_item in enumerate(prefs.preferences.search_paths):
row = box.row()
row.prop(path_item, "path", text=f"Search path {i+1}")
# Folder icon for browsing (FMT-style)
row.operator("dlm.browse_search_path", text="", icon='FILE_FOLDER').index = i
# Remove button (FMT-style)
row.operator("dlm.remove_search_path", text="", icon='REMOVE').index = i
# Add button (FMT-style) - Just the + button, right-justified
row = box.row()
row.alignment = 'RIGHT'
row.operator("dlm.add_search_path", text="", icon='ADD')
# Main action button (FMT-style)
missing_count = sum(1 for lib in props.linked_libraries if lib.is_missing)
if missing_count > 0:
row = box.row()
row.operator("dlm.fmt_style_find", text="Find libraries in these folders", icon='VIEWZOOM')
# Asset replacement section (FMT-style)
box = layout.box()
box.label(text="Asset Replacement")
obj = context.active_object
if obj:
box.label(text=f"Selected: {obj.name}")
# Check if object itself is linked
if obj.library:
box.label(text=f"Linked from: {obj.library.filepath}")
row = box.row()
row.operator("dlm.replace_linked_asset", text="Replace Asset")
# Check if object's data is linked
elif obj.data and obj.data.library:
box.label(text=f"Data linked from: {obj.data.library.filepath}")
row = box.row()
row.operator("dlm.replace_linked_asset", text="Replace Asset")
# Check if it's a linked armature
elif obj.type == 'ARMATURE' and obj.data and hasattr(obj.data, 'library') and obj.data.library:
box.label(text=f"Armature linked from: {obj.data.library.filepath}")
row = box.row()
row.operator("dlm.replace_linked_asset", text="Replace Asset")
else:
box.label(text="Not a linked asset")
else:
box.label(text="No object selected")
# Settings section (FMT-style)
box = layout.box()
box.label(text="Settings")
row = box.row()
row.prop(props, "selected_asset_path", text="Asset Path")
def register():
bpy.utils.register_class(SearchPathItem)
bpy.utils.register_class(LinkedDatablockItem)
bpy.utils.register_class(DYNAMICLINK_UL_library_list)
bpy.utils.register_class(LinkedLibraryItem)
bpy.utils.register_class(DynamicLinkManagerProperties)
bpy.utils.register_class(DynamicLinkManagerPreferences)
bpy.utils.register_class(DLM_PT_main_panel)
# Register properties to scene
bpy.types.Scene.dynamic_link_manager = bpy.props.PointerProperty(type=DynamicLinkManagerProperties)
def unregister():
# Unregister properties from scene
del bpy.types.Scene.dynamic_link_manager
bpy.utils.unregister_class(DLM_PT_main_panel)
bpy.utils.unregister_class(DynamicLinkManagerPreferences)
bpy.utils.unregister_class(DynamicLinkManagerProperties)
bpy.utils.unregister_class(LinkedLibraryItem)
bpy.utils.unregister_class(DYNAMICLINK_UL_library_list)
bpy.utils.unregister_class(LinkedDatablockItem)
bpy.utils.unregister_class(SearchPathItem)