Skip to content

extract_workfile

ExtractWorkfile

Bases: Extractor

Extractor export Hiero workfile representation

Source code in client/ayon_hiero/plugins/publish/extract_workfile.py
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
82
83
84
85
class ExtractWorkfile(publish.Extractor):
    """
    Extractor export Hiero workfile representation
    """

    label = "Extract Workfile"
    order = pyblish.api.ExtractorOrder
    families = ["workfile"]
    hosts = ["hiero"]

    def process(self, instance):
        # create representation data
        if "representations" not in instance.data:
            instance.data["representations"] = []

        # asset = instance.context.data["folderPath"]
        # asset_name = asset.split("/")[-1]

        active_timeline = hiero.ui.activeSequence()
        # project = active_timeline.project()

        # adding otio timeline to context
        # otio_timeline = hiero_export.create_otio_timeline()
        # otio_timeline = instance.data["otioTimeline"]

        # get workfile thumbnail paths
        tmp_staging = tempfile.mkdtemp(prefix="pyblish_tmp_")
        thumbnail_name = "workfile_thumbnail.png"
        thumbnail_path = os.path.join(tmp_staging, thumbnail_name)

        # search for all windows with name of actual sequence
        _windows = [w for w in hiero.ui.windowManager().windows()
                    if active_timeline.name() in w.windowTitle()]

        # export window to thumb path
        QPixmap.grabWidget(_windows[-1]).save(thumbnail_path, 'png')

        # thumbnail
        thumb_representation = {
            'files': thumbnail_name,
            'stagingDir': tmp_staging,
            'name': "thumbnail",
            'thumbnail': True,
            'ext': "png"
        }

        name = instance.data["name"]
        project = hiero.ui.activeProject()
        staging_dir = self.staging_dir(instance)

        ext = ".hrox"
        filename = name + ext
        filepath = os.path.normpath(
            os.path.join(staging_dir, filename))

        # write out the workfile
        path_previous = project.path()
        project.saveAs(filepath)
        project.setPath(path_previous)

        # create workfile representation
        representation = {
            'name': ext.lstrip("."),
            'ext': ext.lstrip("."),
            'files': filename,
            "stagingDir": staging_dir,
        }
        representations = instance.data.setdefault("representations", [])
        representations.append(representation)
        representations.append(thumb_representation)

        self.log.debug(
            "Added hiero file representation: {}".format(representation)
        )