create context collector also adds thumbnail source to instances

This commit is contained in:
Jakub Trllo 2022-10-27 18:41:53 +02:00
parent d71a1f8d52
commit f5c73f5a94
4 changed files with 36 additions and 10 deletions

View file

@ -40,7 +40,8 @@ class CollectMovieBatch(
if creator_attributes["add_review_family"]:
repre["tags"].append("review")
instance.data["families"].append("review")
instance.data["thumbnailSource"] = file_url
if not instance.data.get("thumbnailSource"):
instance.data["thumbnailSource"] = file_url
instance.data["source"] = file_url

View file

@ -188,7 +188,8 @@ class CollectSettingsSimpleInstances(pyblish.api.InstancePlugin):
if "review" not in instance.data["families"]:
instance.data["families"].append("review")
instance.data["thumbnailSource"] = first_filepath
if not instance.data.get("thumbnailSource"):
instance.data["thumbnailSource"] = first_filepath
review_representation["tags"].append("review")
self.log.debug("Representation {} was marked for review. {}".format(

View file

@ -42,7 +42,15 @@ class ExtractThumbnailFromSource(pyblish.api.InstancePlugin):
"Processing instance with subset name {}".format(subset_name)
)
# Check if already has thumbnail created
if self._already_has_thumbnail(instance):
self.log.info("Thumbnail representation already present.")
return
thumbnail_source = instance.data.get("thumbnailSource")
if not thumbnail_source:
thumbnail_source = instance.context.data.get("thumbnailSource")
if not thumbnail_source:
self.log.debug("Thumbnail source not filled. Skipping.")
return
@ -53,11 +61,6 @@ class ExtractThumbnailFromSource(pyblish.api.InstancePlugin):
thumbnail_source))
return
# Check if already has thumbnail created
if self._already_has_thumbnail(instance):
self.log.info("Thumbnail representation already present.")
return
# Create temp directory for thumbnail
# - this is to avoid "override" of source file
dst_staging = tempfile.mkdtemp(prefix="pyblish_tmp_")

View file

@ -19,14 +19,28 @@ class CollectFromCreateContext(pyblish.api.ContextPlugin):
if not create_context:
return
thumbnail_paths_by_instance_id = (
create_context.thumbnail_paths_by_instance_id
)
context.data["thumbnailSource"] = (
thumbnail_paths_by_instance_id.get(None)
)
project_name = create_context.project_name
if project_name:
context.data["projectName"] = project_name
for created_instance in create_context.instances:
instance_data = created_instance.data_to_store()
if instance_data["active"]:
thumbnail_path = thumbnail_paths_by_instance_id.get(
created_instance.id
)
self.create_instance(
context, instance_data, created_instance.transient_data
context,
instance_data,
created_instance.transient_data,
thumbnail_path
)
# Update global data to context
@ -39,7 +53,13 @@ class CollectFromCreateContext(pyblish.api.ContextPlugin):
legacy_io.Session[key] = value
os.environ[key] = value
def create_instance(self, context, in_data, transient_data):
def create_instance(
self,
context,
in_data,
transient_data,
thumbnail_path
):
subset = in_data["subset"]
# If instance data already contain families then use it
instance_families = in_data.get("families") or []
@ -53,7 +73,8 @@ class CollectFromCreateContext(pyblish.api.ContextPlugin):
"name": subset,
"family": in_data["family"],
"families": instance_families,
"representations": []
"representations": [],
"thumbnailSource": thumbnail_path
})
for key, value in in_data.items():
if key not in instance.data: