AnimCupboard: ID Management Pie #127

Merged
Demeter Dzadik merged 11 commits from Mets/blender-studio-pipeline:AnimCupboard-relationship-viewer into main 2023-07-19 14:43:14 +02:00
Showing only changes of commit 2f120ba69c - Show all commits

View File

@ -37,17 +37,18 @@ class IDMAN_MT_relationship_pie(bpy.types.Menu):
pie.operator('outliner.better_purge', icon='TRASH')
# ^
remap = pie.operator(
'outliner.remap_users', icon='FILE_REFRESH', text="Remap Users"
)
id = self.get_id(context)
id_type = ID_CLASS_TO_IDENTIFIER.get(type(id))
if not id_type:
pass # TODO
remap.id_type = id_type
remap.id_name_source = id.name
if id.library:
remap.library_path_source = id.library.filepath
if id_type:
remap = pie.operator(
'outliner.remap_users', icon='FILE_REFRESH', text="Remap Users"
)
remap.id_type = id_type
remap.id_name_source = id.name
if id.library:
remap.library_path_source = id.library.filepath
else:
pie.label(text="Cannot remap unknwon ID type: " + str(type(id)))
# ^>
id = OUTLINER_OT_relink_overridden_asset.get_id(context)
@ -200,17 +201,10 @@ class OUTLINER_OT_remap_users(bpy.types.Operator):
bl_options = {'INTERNAL', 'UNDO'}
def update_library_path(self, context):
def get_source_id():
# WTF??? When I try to access this through self, it says it doesn't exist... so I had to duplicate it!? TODO
storage = get_id_storage(self.id_type)
if self.library_path_source:
return storage.get((self.id_name_source, self.library_path_source))
return storage.get((self.id_name_source, None))
# Prepare the ID selector.
remap_targets = context.scene.remap_targets
remap_targets.clear()
source_id = get_source_id()
source_id = get_id(self.id_name_source, self.id_type, self.library_path_source)
for id in get_id_storage(self.id_type):
if id == source_id:
continue
@ -220,18 +214,6 @@ class OUTLINER_OT_remap_users(bpy.types.Operator):
id_entry = remap_targets.add()
id_entry.name = id.name
def get_source_id(self):
storage = get_id_storage(self.id_type)
if self.library_path_source:
return storage.get((self.id_name_source, self.library_path_source))
return storage.get((self.id_name_source, None))
def get_target_id(self):
storage = get_id_storage(self.id_type)
if self.library_path != 'Local Data':
return storage.get((self.id_name_target, self.library_path))
return storage.get((self.id_name_target, None))
library_path: StringProperty(
name="Library",
description="Library path, if we want to remap to a linked ID",
@ -259,10 +241,10 @@ class OUTLINER_OT_remap_users(bpy.types.Operator):
remap_target_libraries.clear()
local = remap_target_libraries.add()
local.name = "Local Data"
source_id_type = type(self.get_source_id())
source_id = get_id(self.id_name_source, self.id_type, self.library_path_source)
for lib in bpy.data.libraries:
for id in lib.users_id:
if type(id) == source_id_type:
if type(id) == type(source_id):
lib_entry = remap_target_libraries.add()
lib_entry.name = lib.filepath
break
@ -278,7 +260,7 @@ class OUTLINER_OT_remap_users(bpy.types.Operator):
scene = context.scene
row = layout.row()
id = self.get_source_id()
id = get_id(self.id_name_source, self.id_type, self.library_path_source)
id_icon = get_datablock_icon(id)
split = row.split()
split.row().label(text="Anything that was referencing this:")
@ -316,8 +298,8 @@ class OUTLINER_OT_remap_users(bpy.types.Operator):
)
return {'CANCELLED'}
source_id = self.get_source_id()
target_id = self.get_target_id()
source_id = get_id(self.id_name_source, self.id_type, self.library_path_source)
target_id = get_id(self.id_name_target, self.id_type, self.library_path)
source_id.user_remap(target_id)
return {'FINISHED'}
@ -424,6 +406,13 @@ def get_id_storage(id_type) -> "bpy.data.something":
return getattr(bpy.data, storage)
def get_id(id_name: str, id_type: str, lib_path=""):
storage = get_id_storage(id_type)
if lib_path:
return storage.get((id_name, lib_path))
return storage.get((id_name, None))
### Library utilities
def get_library_icon(library: bpy.types.Library) -> str:
"""Return the library or the broken library icon, as appropriate."""