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