Skip to content

extract_redshiftproxy

ExtractRedshiftProxy

Bases: Extractor

Extract a Redshift Proxy

Source code in client/ayon_cinema4d/plugins/publish/extract_redshiftproxy.py
 8
 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
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
class ExtractRedshiftProxy(publish.Extractor):
    """Extract a Redshift Proxy"""

    label = "Redshift Proxy"
    hosts = ["cinema4d"]
    families = ["redshiftproxy"]

    def process(self, instance):

        doc: c4d.BaseDocument = instance.context.data["doc"]

        # Collect the start and end including handles
        start = instance.data["frameStartHandle"]
        end = instance.data["frameEndHandle"]
        step = instance.data.get("step", 1)

        export_nodes = instance[:]
        # Define extract output file path
        dir_path = self.staging_dir(instance)

        # Add the `_` suffix because Redshift Proxy export will add the
        # frame numbers to the file names before the extension.
        filename = "{0}_.rs".format(instance.name)
        path = os.path.join(dir_path, filename)

        # TODO: Set the document timeline to 'fit' the extra frame start and
        #  frame end because redshift export fails if the frame range is
        #  outside of the current document's timeline range.

        # Perform alembic extraction
        with lib.maintained_selection():
            lib.set_selection(doc, export_nodes)

            # Export selection to camera
            exporters.extract_redshiftproxy(
                path,
                frame_start=start,
                frame_end=end,
                frame_step=step,
                selection=True,
                doc=doc,
                # Log the applied options to the publish logs
                verbose=True
            )

        # The Redshift exporter will add the frame numbers to the filepath
        # before the extension. So we collect the resulting files.
        frame_filepaths: "list[str]" = []
        for frame in range(int(start), int(end) + 1):
            head, tail = os.path.splitext(path)
            frame_filepath = f"{head}{frame:04d}{tail}"
            if not os.path.exists(frame_filepath):
                raise publish.PublishError(
                    "Expected exported Redshift Proxy frame not found: "
                    f"{frame_filepath}")

            frame_filepaths.append(frame_filepath)

        # Define the collected filename with the frame numbers
        frame_filenames = [os.path.basename(path) for path in frame_filepaths]
        if len(frame_filepaths) == 1:
            files = frame_filenames[0]
        else:
            files = frame_filenames

        representation = {
            "name": "rs",
            "ext": "rs",
            "files": files,
            "stagingDir": dir_path,
        }
        instance.data.setdefault("representations", []).append(representation)

        self.log.info(f"Extracted instance '{instance.name}' to: {path}")