substancepainter use folder and task entity

This commit is contained in:
Jakub Trllo 2024-03-04 16:34:00 +01:00
parent 095b880bd5
commit 007b9aa3da
3 changed files with 43 additions and 28 deletions

View file

@ -245,16 +245,15 @@ class SubstanceHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost):
return
# Prepare formatting data if we detect any path which might have
# template tokens like {asset} in there.
# template tokens like {folder[name]} in there.
formatting_data = {}
has_formatting_entries = any("{" in item["value"] for item in shelves)
if has_formatting_entries:
project_name = self.get_current_project_name()
asset_name = self.get_current_folder_path()
folder_path = self.get_current_folder_path()
task_name = self.get_current_task_name()
project_settings = get_project_settings(project_name)
formatting_data = get_template_data_with_names(
project_name, asset_name, task_name, project_settings
project_name, folder_path, task_name, project_settings
)
anatomy = Anatomy(project_name)
formatting_data["root"] = anatomy.roots

View file

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
"""Creator plugin for creating workfiles."""
import ayon_api
from ayon_core.pipeline import CreatedInstance, AutoCreator
from ayon_core.client import get_asset_by_name
from ayon_core.hosts.substancepainter.api.pipeline import (
set_instances,
@ -29,7 +30,7 @@ class CreateWorkfile(AutoCreator):
variant = self.default_variant
project_name = self.project_name
asset_name = self.create_context.get_current_asset_name()
folder_path = self.create_context.get_current_folder_path()
task_name = self.create_context.get_current_task_name()
host_name = self.create_context.host_name
@ -41,42 +42,51 @@ class CreateWorkfile(AutoCreator):
if instance.creator_identifier == self.identifier
), None)
if current_instance is None:
current_instance_asset = None
else:
current_instance_asset = current_instance["folderPath"]
current_folder_path = None
if current_instance is not None:
current_folder_path = current_instance["folderPath"]
if current_instance is None:
self.log.info("Auto-creating workfile instance...")
asset_doc = get_asset_by_name(project_name, asset_name)
folder_entity = ayon_api.get_folder_by_path(
project_name, folder_path
)
task_entity = ayon_api.get_task_by_name(
project_name, folder_entity["id"], task_name
)
product_name = self.get_product_name(
project_name,
asset_doc,
task_name,
folder_entity,
task_entity,
variant,
host_name,
)
data = {
"folderPath": asset_name,
"folderPath": folder_path,
"task": task_name,
"variant": variant
}
current_instance = self.create_instance_in_context(product_name,
data)
elif (
current_instance_asset != asset_name
current_folder_path != folder_path
or current_instance["task"] != task_name
):
# Update instance context if is not the same
asset_doc = get_asset_by_name(project_name, asset_name)
folder_entity = ayon_api.get_folder_by_path(
project_name, folder_path
)
task_entity = ayon_api.get_task_by_name(
project_name, folder_entity["id"], task_name
)
product_name = self.get_product_name(
project_name,
asset_doc,
task_name,
folder_entity,
task_entity,
variant,
host_name,
)
current_instance["folderPath"] = asset_name
current_instance["folderPath"] = folder_path
current_instance["task"] = task_name
current_instance["productName"] = product_name

View file

@ -1,16 +1,16 @@
import os
import copy
import pyblish.api
from ayon_core.pipeline import publish
import pyblish.api
import ayon_api
import substance_painter.textureset
from ayon_core.pipeline import publish
from ayon_core.hosts.substancepainter.api.lib import (
get_parsed_export_maps,
strip_template
)
from ayon_core.pipeline.create import get_product_name
from ayon_core.client import get_asset_by_name
class CollectTextureSet(pyblish.api.InstancePlugin):
@ -26,10 +26,17 @@ class CollectTextureSet(pyblish.api.InstancePlugin):
def process(self, instance):
config = self.get_export_config(instance)
asset_doc = get_asset_by_name(
instance.context.data["projectName"],
project_name = instance.context.data["projectName"]
folder_entity = ayon_api.get_folder_by_path(
project_name,
instance.data["folderPath"]
)
task_name = instance.data.get("task")
task_entity = None
if folder_entity and task_name:
task_entity = ayon_api.get_task_by_name(
project_name, folder_entity["id"], task_name
)
instance.data["exportConfig"] = config
maps = get_parsed_export_maps(config)
@ -41,12 +48,12 @@ class CollectTextureSet(pyblish.api.InstancePlugin):
for template, outputs in template_maps.items():
self.log.info(f"Processing {template}")
self.create_image_instance(instance, template, outputs,
asset_doc=asset_doc,
task_entity=task_entity,
texture_set_name=texture_set_name,
stack_name=stack_name)
def create_image_instance(self, instance, template, outputs,
asset_doc, texture_set_name, stack_name):
task_entity, texture_set_name, stack_name):
"""Create a new instance per image or UDIM sequence.
The new instances will be of product type `image`.
@ -84,8 +91,7 @@ class CollectTextureSet(pyblish.api.InstancePlugin):
# for now this is only done so the product name starts with
# 'texture'
project_name=context.data["projectName"],
asset_doc=asset_doc,
task_name=instance.data.get("task"),
task_entity=task_entity,
host_name=context.data["hostName"],
product_type="texture",
variant=instance.data["variant"] + suffix,