예제 #1
0
def main():
    """
    Averages marker position from selected markers.
    """
    selection = maya.cmds.ls(selection=True, long=True) or []
    selected_markers = filternodes.get_marker_nodes(selection)
    if len(selected_markers) < 2:
        LOG.warning('Please select more than 1 marker')
        return

    mkr_selection = selected_markers[0]
    mkr = mmapi.Marker(node=mkr_selection)
    # getting camera from the selected marker
    cam_from_mkr = mkr.get_camera()
    mkr_name = mmapi.get_marker_name('avgMarker1')
    new_mkr = mmapi.Marker().create_node(cam=cam_from_mkr, name=mkr_name)

    new_mkr_node = new_mkr.get_node()
    bnd_name = mmapi.get_bundle_name('avgBundle1')
    new_bnd = mmapi.Bundle().create_node(name=bnd_name)
    # connecting bundle to the marker
    new_mkr.set_bundle(new_bnd)

    # getting first frame and last frame from the selected markers
    start_frame, end_frame = lib.__get_markers_start_end_frames(
        selected_markers)

    # Running average from selected markers for giving frame range
    lib.__set_average_marker_position(selected_markers, start_frame, end_frame,
                                      new_mkr_node)

    maya.cmds.select(new_mkr_node)
    # dgdirty for Channel box value update
    maya.cmds.dgdirty(new_mkr_node)
    return None
예제 #2
0
def main():
    """
    Renames selected markers and connected bundles.
    """
    selection = maya.cmds.ls(selection=True, long=True) or []

    selected_markers = filternodes.get_marker_nodes(selection)
    if not selected_markers:
        LOG.warning('Please select markers')
        return

    title = const.TITLE
    message = const.MESSAGE
    text = const.MARKER_NAME
    marker_name = lib.prompt_for_new_node_name(title, message, text)
    # if user clicks cancel on prompt window it returns "None"
    if not marker_name:
        return

    mkr_suffix = const.MARKER_SUFFIX
    bnd_suffix = const.BUNDLE_SUFFIX
    if marker_name == text:
        bundle_name = const.BUNDLE_NAME
    else:
        bundle_name = marker_name

    total_mkrs = len(selected_markers)
    for number, marker in enumerate(reversed(selected_markers)):
        num_str = '%02d' % (total_mkrs - number)
        new_mkr_name = mmapi.get_marker_name(num_str,
                                             prefix=marker_name,
                                             suffix=mkr_suffix)

        mkr = mmapi.Marker(node=marker)
        mkr_node = mkr.get_node()
        maya.cmds.rename(mkr_node, new_mkr_name)

        bnd = mkr.get_bundle()
        # checking if marker is connected to bundle
        if not bnd:
            msg = 'Cannot find bundle connected to Marker; mkr_node=%r'
            LOG.warning(msg, mkr_node)
            continue

        new_bnd_name = mmapi.get_bundle_name(num_str,
                                             prefix=bundle_name,
                                             suffix=bnd_suffix)
        bnd_node = bnd.get_node()
        maya.cmds.rename(bnd_node, new_bnd_name)
    return
예제 #3
0
def create_bundle():
    """
    Create a new Bundle, attached to the selected Marker (if a Marker
    is selected)
    """
    sel = maya.cmds.ls(sl=True, long=True)
    mkr_nodes = filter_nodes.get_marker_nodes(sel)

    bnd_name = mmapi.get_bundle_name('bundle1')
    bnd = mmapi.Bundle().create_node(name=bnd_name)

    bnd_node = bnd.get_node()
    for mkr_node in mkr_nodes:
        linkmarkerbundle_lib.link_marker_bundle(mkr_node, bnd_node)

    maya.cmds.select(bnd.get_node(), replace=True)
    return
예제 #4
0
def __create_node(mkr_data, cam, mkr_grp, with_bundles):
    """
    Create a Marker object from a MarkerData object.
    """
    if isinstance(mkr_data, interface.MarkerData) is False:
        msg = 'mkr_data must be of type: %r'
        raise TypeError(msg % interface.MarkerData.__name__)
    if isinstance(with_bundles, bool) is False:
        msg = 'with_bundles must be of type: %r'
        raise TypeError(msg % bool.__name__)

    name = mkr_data.get_name()
    mkr_name = mmapi.get_marker_name(name)
    bnd_name = mmapi.get_bundle_name(name)
    bnd = None
    mmapi.load_plugin()
    if with_bundles is True:
        bnd = mmapi.Bundle().create_node(bnd_name)
    mkr = mmapi.Marker().create_node(name=mkr_name, cam=cam, mkr_grp=mkr_grp, bnd=bnd)
    return mkr
예제 #5
0
def create_marker():
    """
    Create a new marker under the current viewport camera, or under
    the selected camera, if a camera is selected.
    """
    mmapi.load_plugin()

    sel = maya.cmds.ls(sl=True, long=True)
    node_filtered = filter_nodes.get_nodes(sel)
    cams = node_filtered['camera']
    cams = filter(is_not_startup_cam, cams)
    mkr_grps = node_filtered['markergroup']

    cam = None
    mkr_grp = None
    if len(cams) > 0 and len(mkr_grps) > 0:
        msg = 'Please select a camera or marker group; '
        msg += 'both node types are selected.'
        LOG.error(msg)

    elif len(cams) == 0 and len(mkr_grps) == 0:
        node = __get_camera()
        if node is None:
            msg = 'Please activate a viewport to get a camera.'
            LOG.error(msg)
            return
        if is_startup_cam(node) is True:
            msg = "Cannot create Markers in 'persp' camera."
            LOG.error(msg)
            return
        if maya.cmds.nodeType(node) == 'transform':
            cam = mmapi.Camera(transform=node)
        elif maya.cmds.nodeType(node) == 'camera':
            cam = mmapi.Camera(shape=node)
        else:
            LOG.error('Camera node is invalid; %r', node)
            return

    elif len(cams) > 0 and len(mkr_grps) == 0:
        node = cams[0]
        if maya.cmds.nodeType(node) == 'transform':
            cam = mmapi.Camera(transform=node)
        elif maya.cmds.nodeType(node) == 'camera':
            cam = mmapi.Camera(shape=node)
        else:
            LOG.error('Camera node is invalid; %r', node)
            return

    elif len(cams) == 0 and len(mkr_grps) > 0:
        node = mkr_grps[0]
        mkr_grp = mmapi.MarkerGroup(name=node)

    else:
        LOG.error('Should not get here.')

    bnd_name = mmapi.get_bundle_name('bundle1')
    bnd = mmapi.Bundle().create_node(
        name=bnd_name
    )

    mkr_name = mmapi.get_marker_name('marker1')
    mkr = mmapi.Marker().create_node(
        name=mkr_name,
        cam=cam,
        mkr_grp=mkr_grp,
        bnd=bnd
    )

    maya.cmds.select(mkr.get_node(), replace=True)
    return
예제 #6
0
def main():
    """
    Main function runs duplicate marker on all selected markers.
    """
    selection = maya.cmds.ls(selection=True, long=True) or []
    selected_markers = filternodes.get_marker_nodes(selection)
    if not selected_markers:
        LOG.warning('Please select markers')
        return

    mkr_selection = selected_markers[0]
    mkr = mmapi.Marker(node=mkr_selection)
    # getting camera from the selected marker
    cam_from_mkr = mkr.get_camera()

    # For lock state
    mkr_attrs = const.MKR_ATTRS

    new_mkr_nodes = []
    for marker in selected_markers:
        # Get Marker's name
        mkr = mmapi.Marker(node=marker)
        # old_mkr_node is expected to be a long name.
        old_mkr_node = mkr.get_node()
        if old_mkr_node is None:
            LOG.warning('Invalid Marker, skipping duplicate.')
            continue
        mkr_name = old_mkr_node.rpartition('|')[-1]
        mkr_name = mkr_name[0].upper() + mkr_name[1:]
        mkr_name = 'dup' + mkr_name

        # Get Bundles's name
        bnd_name = 'dupBundle1'
        bnd = mkr.get_bundle()
        if bnd is None:
            pass
        else:
            bnd_node = bnd.get_node()
            bnd_name = bnd_node.rpartition('|')[-1]
            bnd_name = bnd_name[0].upper() + bnd_name[1:]
            bnd_name = 'dup' + bnd_name

        # get attrs lock state
        lock_value = lib.__get_lock_state(marker, mkr_attrs)

        mkr_name = mmapi.get_marker_name(mkr_name)
        new_mkr = mmapi.Marker().create_node(cam=cam_from_mkr, name=mkr_name)
        new_mkr_node = new_mkr.get_node()
        bnd_name = mmapi.get_bundle_name(bnd_name)
        new_bnd = mmapi.Bundle().create_node(name=bnd_name)
        # connecting bundle to the marker
        new_mkr.set_bundle(new_bnd)

        # running duplicate
        lib.__copy_key_frames(marker, new_mkr_node)

        # set lock state on newly created markers
        lib.__set_lock_state(new_mkr_node, mkr_attrs, lock_value)
        new_mkr_nodes.append(new_mkr_node)

    if len(new_mkr_nodes) > 0:
        maya.cmds.select(new_mkr_nodes, replace=True)
    else:
        # Restore the original selection.
        maya.cmds.select(selection, replace=True)
    return