Skip to content

extract_redshift_proxy

Redshift Proxy extractor.

ExtractRedshiftProxy

Bases: MayaExtractorPlugin

Extract the content of the instance to a redshift proxy file.

Source code in client/ayon_maya/plugins/publish/extract_redshift_proxy.py
 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
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
class ExtractRedshiftProxy(plugin.MayaExtractorPlugin):
    """Extract the content of the instance to a redshift proxy file."""

    label = "Redshift Proxy (.rs)"
    families = ["redshiftproxy"]

    def process(self, instance):
        """Extractor entry point."""

        # Make sure Redshift is loaded
        cmds.loadPlugin("redshift4maya", quiet=True)

        anim_on: bool = instance.data["animation"]
        if anim_on:
            # Add frame number #### placeholder for animated exports
            file_name = "{}.####.rs".format(instance.name)
        else:
            file_name = "{}.rs".format(instance.name)

        staging_dir = self.staging_dir(instance)
        file_path = os.path.join(staging_dir, file_name)

        rs_options = "exportConnectivity=0;enableCompression=1;keepUnused=0;"
        repr_files: Union[str, list[str]] = file_name
        if not anim_on:
            # Remove animation information because it is not required for
            # non-animated products
            keys = ["frameStart",
                    "frameEnd",
                    "handleStart",
                    "handleEnd",
                    "frameStartHandle",
                    "frameEndHandle"]
            for key in keys:
                instance.data.pop(key, None)

        else:
            start_frame = instance.data["frameStartHandle"]
            end_frame = instance.data["frameEndHandle"]
            rs_options = "{}startFrame={};endFrame={};frameStep={};".format(
                rs_options, start_frame,
                end_frame, instance.data["step"]
            )
            repr_files: list[str] = []
            for frame in range(
                    int(start_frame),
                    int(end_frame) + 1,
                    int(instance.data["step"])):
                frame_padded = str(frame).rjust(4, "0")
                frame_filename = file_name.replace(
                    ".####.rs", f".{frame_padded}.rs"
                )
                repr_files.append(frame_filename)

        # Write out rs file
        self.log.debug("Writing: '%s'", file_path)

        # Allow overriding what renderlayer to export from. By default, force
        # it to the default render layer. (Note that the renderlayer isn't
        # currently exposed as an attribute to artists)
        layer = instance.data.get("renderLayer", "defaultRenderLayer")

        with maintained_selection():
            with renderlayer(layer):
                with allow_export_from_render_setup_layer():
                    cmds.select(instance.data["setMembers"], noExpand=True)
                    cmds.file(file_path,
                              preserveReferences=False,
                              force=True,
                              type="Redshift Proxy",
                              exportSelected=True,
                              options=rs_options)

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

        self.log.debug("Files: {}".format(repr_files))

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

        self.log.debug(
            f"Extracted instance '{instance.name}' to: {staging_dir}"
        )

process(instance)

Extractor entry point.

Source code in client/ayon_maya/plugins/publish/extract_redshift_proxy.py
 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
def process(self, instance):
    """Extractor entry point."""

    # Make sure Redshift is loaded
    cmds.loadPlugin("redshift4maya", quiet=True)

    anim_on: bool = instance.data["animation"]
    if anim_on:
        # Add frame number #### placeholder for animated exports
        file_name = "{}.####.rs".format(instance.name)
    else:
        file_name = "{}.rs".format(instance.name)

    staging_dir = self.staging_dir(instance)
    file_path = os.path.join(staging_dir, file_name)

    rs_options = "exportConnectivity=0;enableCompression=1;keepUnused=0;"
    repr_files: Union[str, list[str]] = file_name
    if not anim_on:
        # Remove animation information because it is not required for
        # non-animated products
        keys = ["frameStart",
                "frameEnd",
                "handleStart",
                "handleEnd",
                "frameStartHandle",
                "frameEndHandle"]
        for key in keys:
            instance.data.pop(key, None)

    else:
        start_frame = instance.data["frameStartHandle"]
        end_frame = instance.data["frameEndHandle"]
        rs_options = "{}startFrame={};endFrame={};frameStep={};".format(
            rs_options, start_frame,
            end_frame, instance.data["step"]
        )
        repr_files: list[str] = []
        for frame in range(
                int(start_frame),
                int(end_frame) + 1,
                int(instance.data["step"])):
            frame_padded = str(frame).rjust(4, "0")
            frame_filename = file_name.replace(
                ".####.rs", f".{frame_padded}.rs"
            )
            repr_files.append(frame_filename)

    # Write out rs file
    self.log.debug("Writing: '%s'", file_path)

    # Allow overriding what renderlayer to export from. By default, force
    # it to the default render layer. (Note that the renderlayer isn't
    # currently exposed as an attribute to artists)
    layer = instance.data.get("renderLayer", "defaultRenderLayer")

    with maintained_selection():
        with renderlayer(layer):
            with allow_export_from_render_setup_layer():
                cmds.select(instance.data["setMembers"], noExpand=True)
                cmds.file(file_path,
                          preserveReferences=False,
                          force=True,
                          type="Redshift Proxy",
                          exportSelected=True,
                          options=rs_options)

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

    self.log.debug("Files: {}".format(repr_files))

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

    self.log.debug(
        f"Extracted instance '{instance.name}' to: {staging_dir}"
    )