Skip to content

extract_animation

ExtractAnimation

Bases: Extractor

Extract FBX Animation

Source code in client/ayon_motionbuilder/plugins/publish/extract_animation.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
class ExtractAnimation(publish.Extractor):
    """
    Extract FBX Animation
    """

    order = pyblish.api.ExtractorOrder + 0.001
    label = "Extract Animation"
    hosts = ["motionbuilder"]
    families = ["animation"]

    def process(self, instance):
        staging_dir = self.staging_dir(instance)
        asset_filename = "{name}.fbx".format(**instance.data)

        filepath = os.path.join(
            staging_dir, asset_filename).replace("\\", "/")

        app = FBApplication()
        saveOptions = FBFbxOptions(False)
        creator_attributes = instance.data["creator_attributes"]
        saveOptions.EmbedMedia = (
            True if creator_attributes.get("EmbedMedia")
            else False)
        saveOptions.KeepTransformHierarchy = (
            True if creator_attributes.get("KeepTransformHierarchy")
            else False)
        # TODO: Select the model which needs to export
        saveOptions.SaveSelectedModelsOnly = (
            True if creator_attributes.get("SaveSelectedModelsOnly")
            else False)
        selected_nodes = [node for node in
                          FBSystem().Scene.RootModel.Children
                          if node.Name in instance.data.get(
                              "selected_nodes", [])]
        with maintain_selection(selected_nodes):
            app.FileSave(filepath, saveOptions)

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