Skip to content

actions

A module containing generic loader actions that will display in the Loader.

ImportMayaLoader

Bases: Loader

Import action for Maya (unmanaged)

Warning

The loaded content will be unmanaged and is not visible in the scene inventory. It's purely intended to merge content into your scene so you could also use it as a new base.

Source code in client/ayon_maya/plugins/load/actions.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
class ImportMayaLoader(ayon_maya.api.plugin.Loader):
    """Import action for Maya (unmanaged)

    Warning:
        The loaded content will be unmanaged and is *not* visible in the
        scene inventory. It's purely intended to merge content into your scene
        so you could also use it as a new base.

    """
    representations = {"ma", "mb", "obj"}
    product_types = {
        "model",
        "pointcache",
        "proxyAbc",
        "animation",
        "mayaAscii",
        "mayaScene",
        "setdress",
        "layout",
        "camera",
        "rig",
        "camerarig",
        "staticMesh",
        "workfile",
    }

    label = "Import"
    order = 10
    icon = "arrow-circle-down"
    color = "#775555"

    options = [
        qargparse.Boolean(
            "clean_import",
            label="Clean import",
            default=False,
            help="Should all occurrences of cbId be purged?"
        )
    ]

    @classmethod
    def apply_settings(cls, project_settings):
        super(ImportMayaLoader, cls).apply_settings(project_settings)
        cls.enabled = cls.load_settings["import_loader"].get("enabled", True)

    def load(self, context, name=None, namespace=None, data=None):
        import maya.cmds as cmds

        choice = self.display_warning()
        if choice is False:
            return

        custom_group_name, custom_namespace, options = \
            self.get_custom_namespace_and_group(context, data,
                                                "import_loader")

        namespace = get_custom_namespace(custom_namespace)

        if not options.get("attach_to_root", True):
            custom_group_name = namespace

        path = self.filepath_from_context(context)
        with maintained_selection():
            nodes = cmds.file(path,
                              i=True,
                              preserveReferences=True,
                              namespace=namespace,
                              returnNewNodes=True,
                              groupReference=options.get("attach_to_root",
                                                         True),
                              groupName=custom_group_name)

            if data.get("clean_import", False):
                remove_attributes = ["cbId"]
                for node in nodes:
                    for attr in remove_attributes:
                        if cmds.attributeQuery(attr, node=node, exists=True):
                            full_attr = "{}.{}".format(node, attr)
                            print("Removing {}".format(full_attr))
                            cmds.deleteAttr(full_attr)

        # We do not containerize imported content, it remains unmanaged
        return

    def display_warning(self):
        """Show warning to ensure the user can't import models by accident

        Returns:
            bool

        """

        from qtpy import QtWidgets

        accept = QtWidgets.QMessageBox.Ok
        buttons = accept | QtWidgets.QMessageBox.Cancel

        message = "Are you sure you want import this"
        state = QtWidgets.QMessageBox.warning(None,
                                              "Are you sure?",
                                              message,
                                              buttons=buttons,
                                              defaultButton=accept)

        return state == accept

display_warning()

Show warning to ensure the user can't import models by accident

Returns:

Type Description

bool

Source code in client/ayon_maya/plugins/load/actions.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
def display_warning(self):
    """Show warning to ensure the user can't import models by accident

    Returns:
        bool

    """

    from qtpy import QtWidgets

    accept = QtWidgets.QMessageBox.Ok
    buttons = accept | QtWidgets.QMessageBox.Cancel

    message = "Are you sure you want import this"
    state = QtWidgets.QMessageBox.warning(None,
                                          "Are you sure?",
                                          message,
                                          buttons=buttons,
                                          defaultButton=accept)

    return state == accept

SetFrameRangeLoader

Bases: LoaderPlugin

Set frame range excluding pre- and post-handles

Source code in client/ayon_maya/plugins/load/actions.py
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
class SetFrameRangeLoader(load.LoaderPlugin):
    """Set frame range excluding pre- and post-handles"""

    product_types = {
        "animation",
        "camera",
        "proxyAbc",
        "pointcache",
    }
    representations = {"abc"}

    label = "Set frame range"
    order = 11
    icon = "clock-o"
    color = "white"

    def load(self, context, name, namespace, data):

        import maya.cmds as cmds

        version_attributes = context["version"]["attrib"]
        start = version_attributes.get("frameStart")
        end = version_attributes.get("frameEnd")

        if start is None or end is None:
            print("Skipping setting frame range because start or "
                  "end frame data is missing..")
            return

        cmds.playbackOptions(minTime=start,
                             maxTime=end,
                             animationStartTime=start,
                             animationEndTime=end)

SetFrameRangeWithHandlesLoader

Bases: LoaderPlugin

Set frame range including pre- and post-handles

Source code in client/ayon_maya/plugins/load/actions.py
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 SetFrameRangeWithHandlesLoader(load.LoaderPlugin):
    """Set frame range including pre- and post-handles"""

    product_types = {
        "animation",
        "camera",
        "proxyAbc",
        "pointcache",
    }
    representations = {"abc"}

    label = "Set frame range (with handles)"
    order = 12
    icon = "clock-o"
    color = "white"

    def load(self, context, name, namespace, data):

        import maya.cmds as cmds

        version_attributes = context["version"]["attrib"]

        start = version_attributes.get("frameStart")
        end = version_attributes.get("frameEnd")

        if start is None or end is None:
            print("Skipping setting frame range because start or "
                  "end frame data is missing..")
            return

        # Include handles
        start -= version_attributes.get("handleStart", 0)
        end += version_attributes.get("handleEnd", 0)

        cmds.playbackOptions(minTime=start,
                             maxTime=end,
                             animationStartTime=start,
                             animationEndTime=end)