Blender Kitsu: New Assset Tagging System #286
@ -250,6 +250,17 @@ class KITSU_OT_con_set_asset(bpy.types.Operator):
|
||||
"Shot Builder, if the Asset is casted to the buider's target shot"
|
||||
)
|
||||
|
||||
_published_file_path: Path = None
|
||||
|
||||
use_asset_pipeline_publish: bpy.props.BoolProperty( # type: ignore
|
||||
name="Use Asset Pipeline Publish",
|
||||
description=(
|
||||
"Find the Publish of this file in the 'Publish' folder and use it's filepath for Kitsu Asset`"
|
||||
"Selected Collection must be named exactly the same between current file and Publish"
|
||||
),
|
||||
default=False,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
kitsu_props = context.scene.kitsu
|
||||
@ -273,8 +284,39 @@ class KITSU_OT_con_set_asset(bpy.types.Operator):
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_asset_pipeline_enabled(self, context) -> bool:
|
||||
for addon in context.preferences.addons:
|
||||
if addon.module == "asset_pipeline":
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_asset_pipeline_publish(self, context) -> Path:
|
||||
from asset_pipeline.merge.publish import find_latest_publish
|
||||
|
||||
return find_latest_publish(Path(bpy.data.filepath))
|
||||
|
||||
def invoke(self, context, event):
|
||||
if self.is_asset_pipeline_enabled(context):
|
||||
self._published_file_path = self.get_asset_pipeline_publish(context)
|
||||
if self._published_file_path.exists():
|
||||
self.use_asset_pipeline_publish = True
|
||||
wm = context.window_manager
|
||||
return wm.invoke_props_dialog(self)
|
||||
return self.execute(context)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
relative_path = self._published_file_path.relative_to(Path(bpy.data.filepath).parent)
|
||||
box = layout.box()
|
||||
box.enabled = self.use_asset_pipeline_publish
|
||||
box.label(text=f"//{str(relative_path)}")
|
||||
layout.prop(self, "use_asset_pipeline_publish")
|
||||
|
||||
def execute(self, context):
|
||||
project_root = prefs.project_root_dir_get(context)
|
||||
if self.use_asset_pipeline_publish:
|
||||
relative_path = self._published_file_path.relative_to(project_root)
|
||||
else:
|
||||
relative_path = Path(bpy.data.filepath).relative_to(project_root)
|
||||
blender_asset = context.scene.kitsu.asset_col
|
||||
kitsu_asset = cache.asset_active_get()
|
||||
@ -284,7 +326,8 @@ class KITSU_OT_con_set_asset(bpy.types.Operator):
|
||||
|
||||
kitsu_asset.set_asset_path(str(relative_path), blender_asset.name)
|
||||
self.report(
|
||||
{"INFO"}, f"Kitsu Asset '{kitsu_asset.name}' set to Collection '{blender_asset.name}'"
|
||||
{"INFO"},
|
||||
f"Kitsu Asset '{kitsu_asset.name}' set to Collection '{blender_asset.name}' at path '{relative_path}'",
|
||||
)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user