Skip to content

collect_comment

Collect comment and add option to enter comment per instance.

Combination of plugins. One define optional input for instances in Publisher UI (CollectInstanceCommentDef) and second cares that each instance during collection has available "comment" key in data (CollectComment).

Plugin 'CollectInstanceCommentDef' define "comment" attribute which won't be filled with any value if instance does not match families filter or when plugin is disabled.

Plugin 'CollectComment' makes sure that each instance in context has available "comment" key in data which can be set to 'str' or 'None' if is not set. - In case instance already has filled comment the plugin's logic is skipped - The comment is always set and value should be always 'str' even if is empty

Why are separated: - 'CollectInstanceCommentDef' can have specific settings to show comment attribute only to defined families in publisher UI - 'CollectComment' will run all the time

Todos

The comment per instance is not sent via farm.

CollectComment

Bases: ContextPlugin, AYONPyblishPluginMixin

Collect comment per each instance.

Plugin makes sure each instance to publish has set "comment" in data so any further plugin can use it directly.

Source code in client/ayon_core/plugins/publish/collect_comment.py
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class CollectComment(
    pyblish.api.ContextPlugin,
    AYONPyblishPluginMixin
):
    """Collect comment per each instance.

    Plugin makes sure each instance to publish has set "comment" in data so any
    further plugin can use it directly.
    """

    label = "Collect Instance Comment"
    # TODO change to CollectorOrder after Pyblish is purged
    # Pyblish allows modifying comment after collect phase
    order = pyblish.api.ExtractorOrder - 0.49

    def process(self, context):
        context_comment = self.cleanup_comment(context.data.get("comment"))
        # Set it back
        context.data["comment"] = context_comment
        for instance in context:
            instance_label = str(instance)
            # Check if comment is already set
            instance_comment = self.cleanup_comment(
                instance.data.get("comment"))

            # If comment on instance is not set then look for attributes
            if not instance_comment:
                attr_values = self.get_attr_values_from_data_for_plugin(
                    CollectInstanceCommentDef, instance.data
                )
                instance_comment = self.cleanup_comment(
                    attr_values.get("comment")
                )

            # Use context comment if instance has all options of comment
            #   empty
            if not instance_comment:
                instance_comment = context_comment

            instance.data["comment"] = instance_comment
            if instance_comment:
                msg_end = "has comment set to: \"{}\"".format(
                    instance_comment)
            else:
                msg_end = "does not have set comment"
            self.log.debug("Instance {} {}".format(instance_label, msg_end))

    def cleanup_comment(self, comment):
        """Cleanup comment value.

        Args:
            comment (Union[str, None]): Comment value from data.

        Returns:
            str: Cleaned comment which is stripped or empty string if input
                was 'None'.
        """

        if comment:
            return comment.strip()
        return ""

cleanup_comment(comment)

Cleanup comment value.

Parameters:

Name Type Description Default
comment Union[str, None]

Comment value from data.

required

Returns:

Name Type Description
str

Cleaned comment which is stripped or empty string if input was 'None'.

Source code in client/ayon_core/plugins/publish/collect_comment.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def cleanup_comment(self, comment):
    """Cleanup comment value.

    Args:
        comment (Union[str, None]): Comment value from data.

    Returns:
        str: Cleaned comment which is stripped or empty string if input
            was 'None'.
    """

    if comment:
        return comment.strip()
    return ""