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') pie.operator('outliner.better_purge', icon='TRASH')
# ^ # ^
id = self.get_id(context)
id_type = ID_CLASS_TO_IDENTIFIER.get(type(id))
if id_type:
remap = pie.operator( remap = pie.operator(
'outliner.remap_users', icon='FILE_REFRESH', text="Remap Users" '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_type = id_type
remap.id_name_source = id.name remap.id_name_source = id.name
if id.library: if id.library:
remap.library_path_source = id.library.filepath 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) 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'} bl_options = {'INTERNAL', 'UNDO'}
def update_library_path(self, context): 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. # Prepare the ID selector.
remap_targets = context.scene.remap_targets remap_targets = context.scene.remap_targets
remap_targets.clear() 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): for id in get_id_storage(self.id_type):
if id == source_id: if id == source_id:
continue continue
@ -220,18 +214,6 @@ class OUTLINER_OT_remap_users(bpy.types.Operator):
id_entry = remap_targets.add() id_entry = remap_targets.add()
id_entry.name = id.name 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( library_path: StringProperty(
name="Library", name="Library",
description="Library path, if we want to remap to a linked ID", 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() remap_target_libraries.clear()
local = remap_target_libraries.add() local = remap_target_libraries.add()
local.name = "Local Data" 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 lib in bpy.data.libraries:
for id in lib.users_id: 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 = remap_target_libraries.add()
lib_entry.name = lib.filepath lib_entry.name = lib.filepath
break break
@ -278,7 +260,7 @@ class OUTLINER_OT_remap_users(bpy.types.Operator):
scene = context.scene scene = context.scene
row = layout.row() 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) id_icon = get_datablock_icon(id)
split = row.split() split = row.split()
split.row().label(text="Anything that was referencing this:") split.row().label(text="Anything that was referencing this:")
@ -316,8 +298,8 @@ class OUTLINER_OT_remap_users(bpy.types.Operator):
) )
return {'CANCELLED'} return {'CANCELLED'}
source_id = self.get_source_id() source_id = get_id(self.id_name_source, self.id_type, self.library_path_source)
target_id = self.get_target_id() target_id = get_id(self.id_name_target, self.id_type, self.library_path)
source_id.user_remap(target_id) source_id.user_remap(target_id)
return {'FINISHED'} return {'FINISHED'}
@ -424,6 +406,13 @@ def get_id_storage(id_type) -> "bpy.data.something":
return getattr(bpy.data, storage) 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 ### Library utilities
def get_library_icon(library: bpy.types.Library) -> str: def get_library_icon(library: bpy.types.Library) -> str:
"""Return the library or the broken library icon, as appropriate.""" """Return the library or the broken library icon, as appropriate."""