Blender Kitsu: New Assset Tagging System #286
@ -256,6 +256,9 @@ class KITSU_OT_con_set_asset(bpy.types.Operator):
|
||||
if bpy.data.filepath == "":
|
||||
cls.poll_message_set("Blend file must be saved")
|
||||
return False
|
||||
if not bpy.data.filepath.startswith(str(prefs.project_root_dir_get(context))):
|
||||
cls.poll_message_set("Blend file must be saved in project structure")
|
||||
return False
|
||||
if not context_core.is_asset_context():
|
||||
cls.poll_message_set("Kitsu Context panel must be set to 'Asset'")
|
||||
return False
|
||||
@ -271,15 +274,15 @@ class KITSU_OT_con_set_asset(bpy.types.Operator):
|
||||
return True
|
||||
|
||||
def execute(self, context):
|
||||
project_root = prefs.project_root_dir_get(context)
|
||||
relative_path = Path(bpy.data.filepath).relative_to(project_root)
|
||||
blender_asset = context.scene.kitsu.asset_col
|
||||
kitsu_asset = cache.asset_active_get()
|
||||
if not kitsu_asset:
|
||||
self.report({"ERROR"}, "Failed to find active Kitsu Asset")
|
||||
return {"CANCELLED"}
|
||||
|
||||
kitsu_asset.set_asset_path(
|
||||
bpy.data.filepath, blender_asset.name, blender_asset.rna_type.name
|
||||
)
|
||||
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}'"
|
||||
)
|
||||
|
@ -735,15 +735,21 @@ class Asset(Entity):
|
||||
asset_dict = gazu.asset.get_asset(asset_id)
|
||||
return cls.from_dict(asset_dict)
|
||||
|
||||
def update(self) -> Asset:
|
||||
gazu.asset.update_asset_data(asdict(self))
|
||||
return self
|
||||
def set_asset_path(self, filepath: str, collection_name: str) -> None:
|
||||
data = {}
|
||||
data["filepath"] = filepath
|
||||
data["collection"] = collection_name
|
||||
updated_asset = gazu.asset.update_asset_data(asdict(self), data)
|
||||
self.data = updated_asset["data"]
|
||||
|
||||
def set_asset_path(self, asset_path: str, asset_name: str, asset_type: str):
|
||||
self.data["asset_path"] = asset_path
|
||||
self.data["asset_name"] = asset_name
|
||||
self.data["asset_type"] = asset_type
|
||||
self.update()
|
||||
if not gazu.project.get_metadata_descriptor_by_field_name(self.project_id, "filepath"):
|
||||
gazu.project.add_metadata_descriptor(
|
||||
self.project_id, "filepath", "Asset", data_type='string'
|
||||
)
|
||||
if not gazu.project.get_metadata_descriptor_by_field_name(self.project_id, "collection"):
|
||||
gazu.project.add_metadata_descriptor(
|
||||
self.project_id, "collection", "Asset", data_type='string'
|
||||
)
|
||||
|
||||
def get_all_task_types(self) -> List[TaskType]:
|
||||
return [TaskType.from_dict(t) for t in gazu.task.all_task_types_for_asset(asdict(self))]
|
||||
|
Loading…
Reference in New Issue
Block a user