Skip to content

extract_batch_workfile

Extract batch group as a consolidated JSON workfile.

ExtractBatchWorkfile

Bases: Extractor

Export the current batch group as a consolidated JSON workfile.

Source code in client/ayon_flame/plugins/publish/extract_batch_workfile.py
 9
10
11
12
13
14
15
16
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
class ExtractBatchWorkfile(publish.Extractor):
    """Export the current batch group as a consolidated JSON workfile."""

    label = "Extract Batch Workfile"
    order = pyblish.api.ExtractorOrder - 0.45
    families = ["workfile"]
    hosts = ["flame"]

    def process(self, instance):
        if instance.data.get("batch_name") is None:
            self.log.warning("No batch_name found in instance data, skipping.")
            return

        if "representations" not in instance.data:
            instance.data["representations"] = []

        batch_name = instance.data.get("batch_name")
        batch = flapi.get_batch_from_workspace(batch_name)
        if not batch:
            raise ValueError(f"Batch group not found: {batch_name}")

        staging_dir = self.staging_dir(instance)
        filename = f"{batch_name}.json"
        filepath = os.path.join(staging_dir, filename)
        flapi.save_batch_as_consolidated_json(batch, filepath)

        representation = {
            "name": "batch",
            "ext": "json",
            "files": filename,
            "stagingDir": staging_dir,
        }
        instance.data["representations"].append(representation)

        # Preserve batch name in version data for reference and loading.
        version_data = instance.data.setdefault("versionData", {})
        version_data["batch_name"] = batch_name

        self.log.info(
            f"Extracted batch workfile representation: {representation}"
        )