Esempio n. 1
0
def reparent_under_node():
    """
    Re-parent the selection under the last selected node.
    """
    frame = maya.cmds.currentTime(query=True)
    nodes = maya.cmds.ls(selection=True, long=True, type='transform') or []

    if len(nodes) < 2:
        msg = ('Not enough objects selected, '
               'select at least 1 child and 1 parent node.')
        LOG.warn(msg)
        return
    with tools_utils.tool_context(disable_viewport=True,
                                  use_undo_chunk=False,
                                  use_dg_evaluation_mode=False,
                                  restore_current_frame=False,
                                  pre_update_frame=False):
        children = nodes[:-1]
        parent = nodes[-1]
        children_tfm_nodes = [
            tfm_utils.TransformNode(node=n) for n in children
        ]
        parent_tfm_node = tfm_utils.TransformNode(node=parent)
        lib.reparent(children_tfm_nodes, parent_tfm_node, sparse=True)
        children = [tn.get_node() for tn in children_tfm_nodes]
        maya.cmds.select(children, replace=True)

    # Trigger Maya to refresh.
    maya.cmds.currentTime(frame, update=True)
    maya.cmds.refresh(currentView=True, force=False)
    return
Esempio n. 2
0
def unparent_to_world():
    """
    Un-parent the selected nodes into world space.
    """
    frame = maya.cmds.currentTime(query=True)
    nodes = maya.cmds.ls(selection=True, long=True, type='transform') or []

    if len(nodes) == 0:
        msg = ('Not enough objects selected, '
               'select at least 1 transform node.')
        LOG.warn(msg)
        return
    with tools_utils.tool_context(disable_viewport=True,
                                  use_undo_chunk=True,
                                  use_dg_evaluation_mode=False,
                                  restore_current_frame=False,
                                  pre_update_frame=False):
        tfm_nodes = [tfm_utils.TransformNode(node=n) for n in nodes]
        lib.reparent(tfm_nodes, None, sparse=True)
        nodes = [tn.get_node() for tn in tfm_nodes]
        maya.cmds.select(nodes, replace=True)

    # Trigger Maya to refresh.
    maya.cmds.currentTime(frame, update=True)
    maya.cmds.refresh(currentView=True, force=False)
    return
Esempio n. 3
0
def reparent_under_node():
    """
    Re-parent the selection under the last selected node.
    """
    frame = maya.cmds.currentTime(query=True)
    nodes = maya.cmds.ls(selection=True, long=True,
                         type='transform') or []
    if len(nodes) < 2:
        msg = ('Not enough objects selected, '
               'select at least 1 child and 1 parent node.')
        LOG.warn(msg)
        return
    try:
        viewport.viewport_turn_off()
        children = nodes[:-1]
        parent = nodes[-1]
        children_tfm_nodes = [tfm_utils.TransformNode(node=n) for n in children]
        parent_tfm_node = tfm_utils.TransformNode(node=parent)
        lib.reparent(children_tfm_nodes, parent_tfm_node, sparse=True)
        children = [tn.get_node() for tn in children_tfm_nodes]
        maya.cmds.select(children, replace=True)
    finally:
        viewport.viewport_turn_on()
    # Trigger Maya to refresh.
    maya.cmds.currentTime(frame, update=True)
    maya.cmds.refresh(currentView=True, force=False)
    return
Esempio n. 4
0
def unparent_to_world():
    """
    Un-parent the selected nodes into world space.
    """
    nodes = maya.cmds.ls(selection=True, long=True, type='transform') or []
    if len(nodes) == 0:
        msg = ('Not enough objects selected, '
               'select at least 1 transform node.')
        LOG.warn(msg)
        return
    tfm_nodes = [tfm_utils.TransformNode(node=n) for n in nodes]
    lib.reparent(tfm_nodes, None, sparse=True)
    nodes = [tn.get_node() for tn in tfm_nodes]
    maya.cmds.select(nodes, replace=True)
    __refresh_maya()
    return
Esempio n. 5
0
    def test_reparent_unparent_with_sparse_keyframes(self):
        name = 'reparent_sparse_keyframes.ma'
        path = self.get_data_path('scenes', name)
        maya.cmds.file(path, open=True, force=True)

        tfm_a = 'pSphere1'
        tfm_b = 'pCube1'
        tfm_node_a = tfm_utils.TransformNode(node=tfm_a)
        tfm_node_b = tfm_utils.TransformNode(node=tfm_b)

        # Parent sphere under cube.
        tfm_nodes = lib.reparent([tfm_node_a],
                                 tfm_node_b,
                                 sparse=True,
                                 delete_static_anim_curves=True)
        tfm_node_c = tfm_nodes[0]

        node = tfm_node_c.get_node()
        plug = node + '.translateX'
        times = maya.cmds.keyframe(plug, query=True, timeChange=True)
        self.assertEqual(len(times), 5)
        self.assertEqual(sorted(times), sorted([1, 16, 61, 98, 120]))
        self.assertEqual(len(tfm_nodes), 1)
        new_parent = tfm_node_a.get_parent()
        self.assertEqual(new_parent, tfm_node_b)

        # Unparent sphere to world
        tfm_nodes = lib.reparent([tfm_node_c],
                                 None,
                                 sparse=True,
                                 delete_static_anim_curves=True)
        tfm_node_d = tfm_nodes[0]

        # save the output
        name = 'reparent_unparent_sparse_with_keyframes_after.ma'
        path = self.get_data_path(name)
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        node = tfm_node_d.get_node()
        plug = node + '.translateX'
        times = maya.cmds.keyframe(plug, query=True, timeChange=True)
        self.assertEqual(len(times), 5)
        self.assertEqual(sorted(times), sorted([1, 16, 61, 98, 120]))
        self.assertEqual(len(tfm_nodes), 1)
        new_parent = tfm_node_a.get_parent()
        self.assertIs(new_parent, None)
Esempio n. 6
0
def reparent_under_node():
    """
    Re-parent the selection under the last selected node.
    """
    nodes = maya.cmds.ls(selection=True, long=True, type='transform') or []
    if len(nodes) < 2:
        msg = ('Not enough objects selected, '
               'select at least 1 child and 1 parent node.')
        LOG.warn(msg)
        return
    children = nodes[:-1]
    parent = nodes[-1]
    children_tfm_nodes = [tfm_utils.TransformNode(node=n) for n in children]
    parent_tfm_node = tfm_utils.TransformNode(node=parent)
    lib.reparent(children_tfm_nodes, parent_tfm_node, sparse=True)
    children = [tn.get_node() for tn in children_tfm_nodes]
    maya.cmds.select(children, replace=True)
    __refresh_maya()
    return
Esempio n. 7
0
def unparent_to_world():
    """
    Un-parent the selected nodes into world space.
    """
    frame = maya.cmds.currentTime(query=True)
    nodes = maya.cmds.ls(selection=True, long=True,
                         type='transform') or []
    if len(nodes) == 0:
        msg = ('Not enough objects selected, '
               'select at least 1 transform node.')
        LOG.warn(msg)
        return
    try:
        viewport.viewport_turn_off()
        tfm_nodes = [tfm_utils.TransformNode(node=n) for n in nodes]
        lib.reparent(tfm_nodes, None, sparse=True)
        nodes = [tn.get_node() for tn in tfm_nodes]
        maya.cmds.select(nodes, replace=True)
    finally:
        viewport.viewport_turn_on()
    # Trigger Maya to refresh.
    maya.cmds.currentTime(frame, update=True)
    maya.cmds.refresh(currentView=True, force=False)
    return
Esempio n. 8
0
    def test_reparent_no_keyframes(self):
        """
        Transform node with no keyframes.
        """
        tfm_node_a, tfm_node_b = self.create_scene_a()
        tfm_nodes = lib.reparent([tfm_node_a],
                                 tfm_node_b,
                                 sparse=True,
                                 delete_static_anim_curves=True)

        # save the output
        name = 'reparent_no_keyframes_after.ma'
        path = self.get_data_path(name)
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.assertEqual(len(tfm_nodes), 1)
        new_tfm_node = tfm_nodes[0]
        new_parent = new_tfm_node.get_parent()
        self.assertEqual(tfm_node_b.get_node(), new_parent.get_node())
        return
Esempio n. 9
0
    def test_unparent_no_keyframes(self):
        """
        Unparent to world, with no keyframes.
        """
        tfm_node_a, tfm_node_b, tfm_node_c = self.create_scene_b()
        tfm_nodes = lib.reparent([tfm_node_b, tfm_node_c],
                                 None,
                                 sparse=True,
                                 delete_static_anim_curves=True)

        # save the output
        name = 'reparent_to_world_no_keyframes_after.ma'
        path = self.get_data_path(name)
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.assertEqual(len(tfm_nodes), 2)
        for tfm_node in tfm_nodes:
            new_parent = tfm_node.get_parent()
            self.assertIs(new_parent, None)
        return