Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

General: Benevolent context label collector #3686

Merged
merged 6 commits into from
Aug 26, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions openpype/plugins/publish/collect_context_label.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Requires:
Optional:
context -> hostName (str)
context -> currentFile (str)
Provides:
context -> label (str)
Expand All @@ -16,16 +17,22 @@ class CollectContextLabel(pyblish.api.ContextPlugin):
label = "Context Label"

def process(self, context):

# Get last registered host
host = pyblish.api.registered_hosts()[-1]

# Get scene name from "currentFile"
path = context.data.get("currentFile") or "<Unsaved>"
base = os.path.basename(path)
# Add ability to use custom context label
context_label = context.data.get("contextLabel")
if context_label:
context.data["label"] = context_label
return
iLLiCiTiT marked this conversation as resolved.
Show resolved Hide resolved

host_name = context.data.get("hostName")
if not host_name:
host_name = pyblish.api.registered_hosts()[-1]
iLLiCiTiT marked this conversation as resolved.
Show resolved Hide resolved
# Use host name as base for label
label = host_name.title()

# Get scene name from "currentFile" and use basename as ending of label
path = context.data.get("currentFile")
if path:
label += " - {}".format(os.path.basename(path))

# Set label
label = "{host} - {scene}".format(host=host.title(), scene=base)
if host == "standalonepublisher":
label = host.title()
context.data["label"] = label