Skip to content

create_psd_workfile

ImageComboCreator

Bases: HiddenTrayPublishCreator

Creates image instance.

Source code in client/ayon_traypublisher/plugins/create/create_psd_workfile.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
class ImageComboCreator(HiddenTrayPublishCreator):
    """Creates image instance."""

    identifier = "io.ayon.creators.traypublisher.psd_workfile_image.image"
    label = "Image"
    host_name = "traypublisher"
    product_base_type = "image"
    product_type = product_base_type

    def create(self, instance_data):
        project_entity = self.create_context.get_current_project_entity()
        folder_path: str = instance_data["folderPath"]
        task_name: Optional[str] = instance_data.get("task")
        # get_current_folder_entity returns None
        folder_entity = self.create_context.get_folder_entity(folder_path)
        task_entity = self.create_context.get_task_entity(
            folder_path, task_name
        )

        project_name = project_entity["name"]
        host_name = self.create_context.host_name

        variant = (
            instance_data.get("variant") or
            next(iter(instance_data["default_variants"]), None)
        )
        product_type = instance_data.get("productType")
        if not product_type:
            product_type = self.product_base_type
        product_name = self.get_product_name(
            project_name=project_name,
            project_entity=project_entity,
            folder_entity=folder_entity,
            task_entity=task_entity,
            variant=variant,
            host_name=host_name,
        )
        new_instance = CreatedInstance(
            product_type=product_type,
            product_base_type=self.product_base_type,
            product_name=product_name,
            data=instance_data,
            creator=self,
        )

        self._store_new_instance(new_instance)

        return new_instance

    def get_instance_attr_defs(self):
        return [
            FileDef(
                "filepath",
                folders=False,
                extensions=[".psd"],
                allow_sequences=False,
                single_item=True,
                label="PSD file",
            ),
            BoolDef(
                "add_review_family",
                default=True,
                label="Review"
            ),
        ]

PSDWorkfileCreator

Bases: TrayPublishCreator

Creates additional image publish instance for provided workfile.

Source code in client/ayon_traypublisher/plugins/create/create_psd_workfile.py
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
class PSDWorkfileCreator(TrayPublishCreator):
    """Creates additional image publish instance for provided workfile."""

    identifier = "io.ayon.creators.traypublisher.psd_workfile_image.workfile"
    label = "PSD Workfile + Image"
    group_label = "Workfile"
    icon = "fa.file"
    description = (
        "Creates additional image publish instances for provided workfile."
    )
    product_base_type = "workfile"
    product_type = product_base_type
    settings_category = "traypublisher"

    default_variants = ["Main"]
    workfile_product_types = []
    image_product_types = []

    def get_detail_description(self):
        return inspect.cleandoc("""# Workfile + Image

        Basic creator that creates image publish instances alongside the main
        workfile instance. 

        Matches existing workflow in WebPublisher 
            ayon+settings://webpublisher/publish/CollectPublishedFiles/task_type_to_product_type/0/value/0/additional_product_types

        .psd workfile could be used both as `workfile` and `image` product.
        Different combos are not currently expected.
        """)

    def create(self, product_name, instance_data, pre_create_data):
        repr_file = pre_create_data.get("filepath")
        if not repr_file:
            raise CreatorError("No files specified")

        instance_data["creator_attributes"] = {
            "filepath": repr_file,
        }

        workfile_product_type = pre_create_data.get("workfile_product_type")
        if not workfile_product_type:
            workfile_product_type = "workfile"
        image_product_type = pre_create_data.get("image_product_type")
        if not image_product_type:
            image_product_type = "image"

        instance_data["default_variants"] = self.default_variants

        workfile_instance = CreatedInstance(
            product_base_type=self.product_base_type,
            product_type=workfile_product_type,
            product_name=product_name,
            data=instance_data,
            creator=self,
        )

        self._store_new_instance(workfile_instance)

        image_creator = self._get_hidden_creator(
            "io.ayon.creators.traypublisher.psd_workfile_image.image"
        )
        if not image_creator:
            raise CreatorError("Image creator not found")

        add_review_family = pre_create_data.get("add_review_family", False)
        image_instance_data = copy.deepcopy(instance_data)
        image_instance_data["creator_attributes"]["add_review_family"] = (
            add_review_family
        )
        image_instance_data["productType"] = image_product_type

        image_creator.create(image_instance_data)

    def _get_hidden_creator(self, identifier):
        creator = self.create_context.creators.get(identifier)
        if creator is None:
            self.log.debug(
                "Creator '%s' not found in create_context.creators", identifier
            )
        return creator

    def get_pre_create_attr_defs(self):
        workfile_product_types = self.workfile_product_types
        image_product_types = self.image_product_types
        if not workfile_product_types:
            workfile_product_types = ["workfile"]
        if not image_product_types:
            image_product_types = ["image"]

        return [
            FileDef(
                "filepath",
                folders=False,
                extensions=[".psd"],
                allow_sequences=False,
                single_item=True,
                label="PSD file",
            ),
            BoolDef(
                "add_review_family",
                default=True,
                label="Review"
            ),
            EnumDef(
                "workfile_product_type",
                label="Workfile product type",
                items=workfile_product_types,
            ),
            EnumDef(
                "image_product_type",
                label="Image product type",
                items=image_product_types,
            ),
        ]

    def get_instance_attr_defs(self):
        return [
            FileDef(
                "filepath",
                folders=False,
                extensions=[".psd"],
                allow_sequences=False,
                single_item=True,
                label="PSD file",
            )
        ]