2025-08-20 17:07:03 -06:00
|
|
|
import bpy
|
2025-08-22 12:25:05 -06:00
|
|
|
from bpy.types import Panel, PropertyGroup, AddonPreferences, UIList
|
2025-08-21 17:18:54 -06:00
|
|
|
from bpy.props import IntProperty, StringProperty, BoolProperty, CollectionProperty
|
|
|
|
|
|
2025-08-22 12:25:05 -06:00
|
|
|
# Properties for search paths
|
|
|
|
|
class SearchPathItem(PropertyGroup):
|
|
|
|
|
path: StringProperty(
|
|
|
|
|
name="Search Path",
|
|
|
|
|
description="Path to search for missing linked libraries",
|
|
|
|
|
subtype='DIR_PATH'
|
|
|
|
|
)
|
|
|
|
|
|
2025-08-21 17:18:54 -06:00
|
|
|
# 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")
|
|
|
|
|
|
2025-08-22 12:25:05 -06:00
|
|
|
# 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)
|
|
|
|
|
|
2025-08-21 17:18:54 -06:00
|
|
|
# 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")
|
2025-08-22 12:01:37 -06:00
|
|
|
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)
|
2025-08-21 17:18:54 -06:00
|
|
|
linked_datablocks: CollectionProperty(type=LinkedDatablockItem, name="Linked Datablocks")
|
2025-08-20 17:07:03 -06:00
|
|
|
|
|
|
|
|
class DynamicLinkManagerProperties(PropertyGroup):
|
2025-08-21 17:18:54 -06:00
|
|
|
linked_libraries: CollectionProperty(type=LinkedLibraryItem, name="Linked Libraries")
|
2025-08-22 12:25:05 -06:00
|
|
|
linked_libraries_index: IntProperty(
|
|
|
|
|
name="Linked Libraries Index",
|
|
|
|
|
description="Index of the selected linked library",
|
|
|
|
|
default=0
|
|
|
|
|
)
|
2025-08-20 17:07:03 -06:00
|
|
|
linked_assets_count: IntProperty(
|
|
|
|
|
name="Linked Assets Count",
|
|
|
|
|
description="Number of linked assets found in scene",
|
|
|
|
|
default=0
|
|
|
|
|
)
|
|
|
|
|
|
2025-08-22 12:01:37 -06:00
|
|
|
linked_libraries_expanded: BoolProperty(
|
|
|
|
|
name="Linked Libraries Expanded",
|
|
|
|
|
description="Whether the linked libraries section is expanded",
|
|
|
|
|
default=True
|
|
|
|
|
)
|
|
|
|
|
|
2025-08-20 17:07:03 -06:00
|
|
|
selected_asset_path: StringProperty(
|
|
|
|
|
name="Selected Asset Path",
|
|
|
|
|
description="Path to the currently selected asset",
|
|
|
|
|
default=""
|
|
|
|
|
)
|
2025-08-22 12:25:05 -06:00
|
|
|
|
|
|
|
|
# FMT-inspired settings
|
|
|
|
|
search_different_extensions: BoolProperty(
|
|
|
|
|
name="Search for libraries with different extensions",
|
|
|
|
|
description="Look for .blend files with different extensions (e.g., .blend1, .blend2)",
|
|
|
|
|
default=False
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
box = layout.box()
|
|
|
|
|
box.label(text="Search Paths for Missing Libraries")
|
|
|
|
|
|
|
|
|
|
# Add/remove search paths
|
|
|
|
|
row = box.row()
|
|
|
|
|
row.operator("dynamiclink.add_search_path", text="Add Search Path", icon='ADD')
|
|
|
|
|
row.operator("dynamiclink.remove_search_path", text="Remove Selected", icon='REMOVE')
|
|
|
|
|
|
|
|
|
|
# List search paths
|
|
|
|
|
for i, path_item in enumerate(self.search_paths):
|
|
|
|
|
row = box.row()
|
|
|
|
|
row.prop(path_item, "path", text=f"Path {i+1}")
|
|
|
|
|
row.operator("dynamiclink.remove_search_path", text="", icon='X').index = i
|
2025-08-20 17:07:03 -06:00
|
|
|
|
|
|
|
|
class DYNAMICLINK_PT_main_panel(Panel):
|
|
|
|
|
bl_space_type = 'VIEW_3D'
|
|
|
|
|
bl_region_type = 'UI'
|
|
|
|
|
bl_category = 'Dynamic Link Manager'
|
|
|
|
|
bl_label = "Asset Replacement"
|
|
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
|
layout = self.layout
|
|
|
|
|
props = context.scene.dynamic_link_manager
|
|
|
|
|
|
2025-08-22 12:25:05 -06:00
|
|
|
# Main scan section (FMT-style)
|
2025-08-20 17:07:03 -06:00
|
|
|
box = layout.box()
|
2025-08-22 12:25:05 -06:00
|
|
|
box.label(text="Linked Libraries Analysis")
|
2025-08-20 17:07:03 -06:00
|
|
|
row = box.row()
|
2025-08-22 12:25:05 -06:00
|
|
|
row.operator("dynamiclink.scan_linked_assets", text="Scan Linked Assets", icon='FILE_REFRESH')
|
|
|
|
|
row.label(text=f"({props.linked_assets_count} libraries)")
|
2025-08-20 17:12:21 -06:00
|
|
|
|
|
|
|
|
# Show more detailed info if we have results
|
|
|
|
|
if props.linked_assets_count > 0:
|
2025-08-22 12:25:05 -06:00
|
|
|
# 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")
|
2025-08-21 17:18:54 -06:00
|
|
|
|
2025-08-22 12:25:05 -06:00
|
|
|
# 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("dynamiclink.open_linked_file", text="Open Selected", icon='FILE_BLEND')
|
|
|
|
|
open_op.filepath = selected_lib.filepath
|
|
|
|
|
else:
|
|
|
|
|
row.operator("dynamiclink.open_linked_file", text="Open Selected", icon='FILE_BLEND')
|
|
|
|
|
row.scale_x = 0.7
|
|
|
|
|
row.operator("dynamiclink.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')
|
2025-08-20 17:07:03 -06:00
|
|
|
|
2025-08-22 12:25:05 -06:00
|
|
|
# Asset replacement section (FMT-style)
|
2025-08-20 17:07:03 -06:00
|
|
|
box = layout.box()
|
|
|
|
|
box.label(text="Asset Replacement")
|
|
|
|
|
|
|
|
|
|
obj = context.active_object
|
|
|
|
|
if obj:
|
|
|
|
|
box.label(text=f"Selected: {obj.name}")
|
2025-08-20 17:28:21 -06:00
|
|
|
|
|
|
|
|
# Check if object itself is linked
|
2025-08-20 17:07:03 -06:00
|
|
|
if obj.library:
|
|
|
|
|
box.label(text=f"Linked from: {obj.library.filepath}")
|
|
|
|
|
row = box.row()
|
|
|
|
|
row.operator("dynamiclink.replace_linked_asset", text="Replace Asset")
|
2025-08-20 17:28:21 -06:00
|
|
|
# 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("dynamiclink.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("dynamiclink.replace_linked_asset", text="Replace Asset")
|
2025-08-20 17:07:03 -06:00
|
|
|
else:
|
|
|
|
|
box.label(text="Not a linked asset")
|
|
|
|
|
else:
|
|
|
|
|
box.label(text="No object selected")
|
|
|
|
|
|
2025-08-22 12:25:05 -06:00
|
|
|
# Search Paths section (FMT-style)
|
2025-08-20 17:07:03 -06:00
|
|
|
box = layout.box()
|
2025-08-22 12:25:05 -06:00
|
|
|
box.label(text="Search Paths for Missing Libraries")
|
|
|
|
|
|
|
|
|
|
# Get preferences
|
|
|
|
|
prefs = context.preferences.addons.get(__package__)
|
|
|
|
|
if prefs:
|
|
|
|
|
# Show current search paths with FMT-style management
|
|
|
|
|
if 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}")
|
|
|
|
|
row.operator("dynamiclink.remove_search_path", text="", icon='X').index = i
|
|
|
|
|
|
|
|
|
|
# Add new search path
|
|
|
|
|
row = box.row()
|
|
|
|
|
row.operator("dynamiclink.add_search_path", text="Add Search Path", icon='ADD')
|
|
|
|
|
|
|
|
|
|
# FMT-inspired settings
|
|
|
|
|
if len(prefs.preferences.search_paths) > 0:
|
|
|
|
|
row = box.row()
|
|
|
|
|
row.prop(props, "search_different_extensions", text="Search for libraries with different extensions")
|
|
|
|
|
|
|
|
|
|
# Find and relink buttons (FMT-style button layout)
|
|
|
|
|
if props.linked_assets_count > 0:
|
|
|
|
|
missing_count = sum(1 for lib in props.linked_libraries if lib.is_missing)
|
|
|
|
|
if missing_count > 0:
|
|
|
|
|
row = box.row()
|
|
|
|
|
row.operator("dynamiclink.find_in_folders", text="Find libraries in these folders", icon='VIEWZOOM')
|
|
|
|
|
row = box.row()
|
|
|
|
|
row.operator("dynamiclink.attempt_relink", text="Attempt to relink found libraries", icon='FILE_REFRESH')
|
2025-08-20 17:07:03 -06:00
|
|
|
|
2025-08-22 12:25:05 -06:00
|
|
|
# Settings section (FMT-style)
|
2025-08-20 17:07:03 -06:00
|
|
|
box = layout.box()
|
|
|
|
|
box.label(text="Settings")
|
|
|
|
|
row = box.row()
|
|
|
|
|
row.prop(props, "selected_asset_path", text="Asset Path")
|
|
|
|
|
|
|
|
|
|
def register():
|
2025-08-22 12:25:05 -06:00
|
|
|
bpy.utils.register_class(SearchPathItem)
|
2025-08-21 17:18:54 -06:00
|
|
|
bpy.utils.register_class(LinkedDatablockItem)
|
2025-08-22 12:25:05 -06:00
|
|
|
bpy.utils.register_class(DYNAMICLINK_UL_library_list)
|
2025-08-21 17:18:54 -06:00
|
|
|
bpy.utils.register_class(LinkedLibraryItem)
|
2025-08-20 17:07:03 -06:00
|
|
|
bpy.utils.register_class(DynamicLinkManagerProperties)
|
2025-08-22 12:25:05 -06:00
|
|
|
bpy.utils.register_class(DynamicLinkManagerPreferences)
|
2025-08-20 17:07:03 -06:00
|
|
|
bpy.utils.register_class(DYNAMICLINK_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(DYNAMICLINK_PT_main_panel)
|
2025-08-22 12:25:05 -06:00
|
|
|
bpy.utils.unregister_class(DynamicLinkManagerPreferences)
|
2025-08-20 17:07:03 -06:00
|
|
|
bpy.utils.unregister_class(DynamicLinkManagerProperties)
|
2025-08-21 17:18:54 -06:00
|
|
|
bpy.utils.unregister_class(LinkedLibraryItem)
|
2025-08-22 12:25:05 -06:00
|
|
|
bpy.utils.unregister_class(DYNAMICLINK_UL_library_list)
|
2025-08-21 17:18:54 -06:00
|
|
|
bpy.utils.unregister_class(LinkedDatablockItem)
|
2025-08-22 12:25:05 -06:00
|
|
|
bpy.utils.unregister_class(SearchPathItem)
|