Exemple #1
0
def get_io_names(robot_name, only_active=False):
    """
    Gets all IOs assigned to the given robot
    :param robot_name: string, name of selected robot
    :param only_active: bool, if True, removes IOs marked as "ignore"
    :return robots_ios: list, names of all IOs on robot
    """

    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot_name)

    # Find all attributes on the target_CTRL categorized as 'io'
    robot_io_names = pm.listAttr(target_ctrl_path, category='io')

    # Remove parent attribute designation 'io_' from each IO name
    for i, io_name in enumerate(robot_io_names):
        robot_io_names[i] = io_name.replace('io_', '')

    # If only_active is True, remove IOs marked as "Ignore"
    if only_active:
        active_ios = [
            x for x in robot_io_names
            if not pm.getAttr(target_ctrl_path + '.' + x + '_ignore')
        ]

        robot_io_names = active_ios

    return robot_io_names
Exemple #2
0
def remove_io(*args):
    """
    Removes IO from the robot it's attached to by deleting all of
    its attributes. The io controller and models are preserved.
    This function just breaks the connection between the robot and the io
    controller
    :param args: required by Maya to call a function from UI button required by Maya UI
    :return:
    """

    # Get the selected item from the Mimic UI
    selection = pm.textScrollList('tsl_ios', selectItem=True, query=True)[0]

    # Split the selection into the robot's name and the IO name
    robot_str, io_name = selection.split(': ')
    pm.select(robot_str)
    robot = mimic_utils.get_robot_roots()[0]

    target_CTRL = mimic_utils.get_target_ctrl_path(robot)

    parent_attribute = '{}.io_{}'.format(target_CTRL, io_name)

    # Delete IO attribute on the robot controller
    pm.deleteAttr(parent_attribute)

    # Clear the io from the Mimic UI selection and reset the UI
    pm.textScrollList('tsl_ios', edit=True, removeItem=selection)
    if not pm.textScrollList('tsl_ios', query=True, numberOfItems=True):
        reset_io_UI()

    pm.select(target_CTRL)
    pm.headsUpMessage('IO \'{}\' removed successfully from {}'.format(
        io_name, robot))
Exemple #3
0
def _show_program_in_output_window(robot, processor, program):
    """
    Display program in the output window.
    :param robot:
    :param processor:
    :param program:
    :return:
    """
    # Update the output-text viewer in the Mimic UI
    details = 'Type of robot     : {} {} ({})\n' \
              'Type of processor : {} {} ({})\n' \
              'Path to template  : {}\n' \
              'Path to output    : {}\n' \
              '\n'

    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot)
    filled_details = details.format(
        mimic_utils.get_robot_type(robot),
        mimic_utils.get_robot_subtype(robot), robot, processor.type_robot,
        processor.type_processor, processor.__class__.__name__,
        postproc.confirm_path_exists(processor.get_program_template_path()),
        postproc.confirm_path_exists(processor.get_program_output_path()))

    pm.scrollField(OUTPUT_WINDOW_NAME, insertText=filled_details, edit=True)

    pm.scrollField(OUTPUT_WINDOW_NAME, insertText=program + '\n', edit=True)
Exemple #4
0
def io_selected(*args):
    """
    Command that is called when an io is selected in IO list
    in Mimic UI, which gets the IO name and info, and updates
    the IO Mimic UI accordingly
    Selects the io controller in Maya's viewport
    :param args: required by Maya to call a function from UI button
    :return:
    """
    # Get the selected item from the Mimic UI
    selection = pm.textScrollList('tsl_ios', selectItem=True, query=True)[0]

    # Split the selection into the robot's name and the IO name
    robot_str, io_name = selection.split(': ')

    # Get selected io' settings
    pm.select(robot_str)
    robot = mimic_utils.get_robot_roots()[0]
    io_info = get_io_info(robot, io_name)

    # Switch Mimic UI to Update IO Mode and populate it with the
    # selected io' info
    update_io_UI(io_info)

    # Select the robot that the IO is assigned to
    target_CTRL = mimic_utils.get_target_ctrl_path(robot)
    pm.select(target_CTRL)
Exemple #5
0
def _get_frames_using_keyframes_only(robot, animation_settings):
    """
    Get frames from animation using a robot's keyframes only.
    :param robot:
    :param animation_settings:
    :return:
    """
    # Get relevant animation parameters.
    start_frame = animation_settings['Start Frame']
    end_frame = animation_settings['End Frame']
    # Get list of keyframes on robots IK attribute for the given range
    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot)
    ik_keyframes = pm.keyframe(target_ctrl_path,
                               attribute='ik',
                               query=True,
                               time='{}:{}'.format(start_frame, end_frame))
    # Verify that there is also a keyframe set on the FK controls' rotate
    # attributes. If there's not, we remove it from the list
    # Note: we only need to check one controller as they are all keyframed
    # together
    fk_test_handle_path = mimic_utils.format_path(
        '{0}|{1}robot_GRP|{1}FK_CTRLS|{1}a1FK_CTRL.rotateY', robot)
    frames = [
        frame for frame in ik_keyframes
        if pm.keyframe(fk_test_handle_path, query=True, time=frame)
    ]
    return frames
Exemple #6
0
def _get_external_axis_path(robot_name, external_axis_name):
    """
    Get the path for an external axis.
    :param robot_name: string, name of robot
    :param external_axis_name: string, name of external axis
    :return:
    """
    return '{}.{}'.format(mimic_utils.get_target_ctrl_path(robot_name), external_axis_name)
Exemple #7
0
def _get_io_path(robot_name, io_name):
    """
    Get the path for an IO.
    :param robot_name: string, name of robot
    :param io_name: string, name of IO
    :return: str, IO attribute path
    """
    return '{}.{}'.format(mimic_utils.get_target_ctrl_path(robot_name),
                          io_name)
Exemple #8
0
def update_io(*args):
    """
    Updates an IO based on user inputs in Mimic UI.
    :param args: required by Maya to call a function from UI button
    """
    # Get the selected item from the Mimic UI
    selection = pm.textScrollList('tsl_ios', selectItem=True, query=True)[0]

    # Split the selection into the robot's name and the IO name
    robot_str, io_name = selection.split(': ')
    pm.select(robot_str)
    robot = mimic_utils.get_robot_roots()[0]

    io_params = _get_io_params()

    io_number = io_params['IO Number']
    postproc_id = io_params['Postproc ID']
    io_type = io_params['Type']
    ignore_in_postproc = io_params['Ignore']

    target_CTRL = mimic_utils.get_target_ctrl_path(robot)

    # Set all IO attributes accordingly
    io_parent_attribute = target_CTRL + '.' + io_name

    # Check that the IO number is unique
    if io_number == pm.getAttr(io_parent_attribute + '_ioNumber'):
        pass
    else:
        _check_io_number(robot, io_number)

    # Set all appropriate attributes on the robot
    # If the robot is referenced, Maya will throw an exceptrion when it
    # tries to lock an attribute
    try:
        pm.setAttr(io_parent_attribute + '_ioNumber', lock=False)
    except:
        pass

    pm.setAttr(io_parent_attribute + '_ioNumber', io_number)

    try:
        pm.setAttr(io_parent_attribute + '_ioNumber', lock=True)
    except:
        pass

    pm.setAttr(io_parent_attribute + '_postprocID', postproc_id)
    pm.setAttr(io_parent_attribute + '_ignore', ignore_in_postproc)

    pm.headsUpMessage('{}: IO \'{}\' successfully updated'.format(
        robot, io_name))

    pm.select(target_CTRL)
Exemple #9
0
def _set_external_axis_CTRL_limits(robot_name, external_axis_CTRL,
                                   external_axis_params):
    """
    Sets the selected external axis controller translation or rotation limits
    :param robot_name: string, name of selected robot
    :param external_axis_CTRL: string, name of external axis controller
    :param external_axis_params: dict, axis parameters set by the user in the 
        Mimic UI
    """

    axis_name = external_axis_params['Axis Name']
    driving_attribute = external_axis_params['Driving Attribute']
    position_limit_min = external_axis_params['Position Limit Min']
    position_limit_max = external_axis_params['Position Limit Max']
    velocity_limit = external_axis_params['Velocity Limit']

    # Break down driving attribute into transform and axis companents
    # 'translateX' becomes 'translate', 'X'
    driving_axis = driving_attribute[-1]

    # Prep transformation string for Maya's limit attributes
    if 'translate' in driving_attribute:
        driving_attribute_trunc = 'Trans'
    else:
        driving_attribute_trunc = 'Rot'

    # Define external axis' attribute path on robot
    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot_name)
    external_axis_min_limit_path = target_ctrl_path + '.{}_axisMin'.format(
        axis_name)

    external_axis_max_limit_path = target_ctrl_path + '.{}_axisMax'.format(
        axis_name)

    # Enable the external axis controllers' limits and connect them to the
    # position attribute on the target controller
    _enable_external_axis_limits(external_axis_CTRL,
                                 driving_attribute_trunc,
                                 driving_axis,
                                 enable=True)

    pm.connectAttr(
        external_axis_min_limit_path,
        '{}.min{}{}Limit'.format(external_axis_CTRL, driving_attribute_trunc,
                                 driving_axis))

    pm.connectAttr(
        external_axis_max_limit_path,
        '{}.max{}{}Limit'.format(external_axis_CTRL, driving_attribute_trunc,
                                 driving_axis))
Exemple #10
0
def _sample_frame_get_axes(robot_name, frame):
    """
    Get robot Axes from an animation frame.
    :param robot_name: Name of the robot
    :param frame: Frame to sample
    :return:
    """
    axes = []
    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot_name)
    for i in range(6):
        axis_number = i + 1  # Axis numbers are 1-indexed
        axis_path = target_ctrl_path + '.axis{}'.format(axis_number)
        axis = pm.getAttr(axis_path, time=frame)
        axes.append(axis)
    return axes
Exemple #11
0
def _connect_remap_node(robot, mFIZ_ctrl, remap_node):
    """
    """
    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot)

    # Connect FIZ attrs from mfIZ node to remap node
    fiz_attrs = FIZ_ATTRS

    for attr in fiz_attrs:
        mFIZ_attr = '{}.{}'.format(mFIZ_ctrl, attr)
        remap_in_attr = '{}.{}'.format(remap_node, attr)
        remap_out_attr = '{}.{}Mapped'.format(remap_node, attr)
        robot_attr = '{}.{}_value'.format(target_ctrl_path, attr)

        pm.connectAttr(mFIZ_attr, remap_in_attr)
        pm.connectAttr(remap_out_attr, robot_attr)
Exemple #12
0
def _check_external_axis_number(robot_name, axis_number):
    """
    Determines if external axis number is unique
    :param robot_name: string, name of robot
    :return:
    """

    # Check that axis name isn't already taken
    robots_external_axes = get_external_axis_names(robot_name)

    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot_name)
    for axis_name in robots_external_axes:
        current_axis_number = pm.getAttr('{}.{}_axisNumber'.format(target_ctrl_path, axis_name))
        if current_axis_number == axis_number:
            raise MimicError('External axis number {} is taken; ' \
                             'axis number must be unique'.format(axis_number))
Exemple #13
0
def _check_external_axis_number(robot_name, axis_number):
    """
    Determines if external axis number is unique
    Raises an Exception if the input axis number is already taken by another
    external axis on the input robot
    :param robot_name: string, name of robot
    :param axis_number: int, user-supplied external axis number
    """

    # Check that axis name isn't already taken
    robots_external_axes = get_external_axis_names(robot_name)

    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot_name)
    for axis_name in robots_external_axes:
        current_axis_number = pm.getAttr('{}.{}_axisNumber'.format(
            target_ctrl_path, axis_name))
        if current_axis_number == axis_number:
            raise MimicError('External axis number {} is taken; ' \
                             'axis number must be unique'.format(axis_number))
Exemple #14
0
def _check_io_number(robot_name, io_number):
    """
    Determines if IO number is unique
    Raises an Exception if the input io number is already taken by another
    IO on the input robot
    :param robot_name: string, name of robot
    :param io_number: int, user-supplied IO number
    """

    # Check that io name isn't already taken
    robots_ios = get_io_names(robot_name)

    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot_name)
    for io_name in robots_ios:
        current_io_number = pm.getAttr('{}.{}_ioNumber'.format(
            target_ctrl_path, io_name))
        if current_io_number == io_number:
            raise MimicError('IO number {} is taken; ' \
                             'io number must be unique'.format(io_number))
Exemple #15
0
def _add_mFIZ_attrs_as_outputs(robot):
    """
    """
    # First, we get the IO numbers currently assigned to the robot and increment
    # ours by 1 to avoid conflicts
    io_numbers = []
    robots_ios = get_io_names(robot)

    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot)

    for io_name in robots_ios:
        io_numbers.append(
            pm.getAttr('{}.{}_ioNumber'.format(target_ctrl_path, io_name)))

    if io_numbers:
        io_number = max(io_numbers) + 1
    else:
        io_number = 1

    # For each FIZ Attribute, create and add IO to the robot
    postproc_id = 0  # Begin postproc_ID attr increment

    fiz_attrs = FIZ_ATTRS

    for attr in fiz_attrs:

        io_param_dict = {}

        io_param_dict['IO Name'] = attr
        io_param_dict['Postproc ID'] = str(postproc_id)
        io_param_dict['IO Number'] = io_number
        io_param_dict['Type'] = 'digital'
        io_param_dict['Resolution'] = '16-bit'
        io_param_dict['Ignore'] = False

        add_io(io_params=io_param_dict)

        io_number += 1
        postproc_id += 16

    pm.headsUpMessage('FIZ outputs added successfully to {}'.format(robot))
Exemple #16
0
def _clear_external_axis_CTRL_limits(robot_name, external_axis_CTRL,
                                     driving_attribute, axis_name):
    """
    Disables the axis limit attributes for the input controller.
    :param robot_name: string, name of selected robot
    :param external_axis_CTRL: string, name of external axis controller
    :param driving_attribute: string, driving attribute e.g. 'rotateX'
    """

    # Break down driving attribute into transform and axis companents
    # 'translateX' becomes 'translate', 'X'
    driving_axis = driving_attribute[-1]

    # Prep transformation string for Maya's limit attributes
    if 'translate' in driving_attribute:
        driving_attribute_trunc = 'Trans'
    else:
        driving_attribute_trunc = 'Rot'

    # Define external axis' attribute path on robot
    target_ctrl_path = mimic_utils.get_target_ctrl_path(robot_name)
    external_axis_min_limit_path = target_ctrl_path + '.{}_axisMin'.format(
        axis_name)

    external_axis_max_limit_path = target_ctrl_path + '.{}_axisMax'.format(
        axis_name)

    _enable_external_axis_limits(external_axis_CTRL,
                                 driving_attribute_trunc,
                                 driving_axis,
                                 enable=False)

    pm.disconnectAttr(
        external_axis_min_limit_path,
        '{}.min{}{}Limit'.format(external_axis_CTRL, driving_attribute_trunc,
                                 driving_axis))

    pm.disconnectAttr(
        external_axis_max_limit_path,
        '{}.max{}{}Limit'.format(external_axis_CTRL, driving_attribute_trunc,
                                 driving_axis))
Exemple #17
0
def add_external_axis(*args):
    """
    Add an external axis to Mimic.
    :param args:
    :return:
    """
    # Get the External Axis' parameters from the Mimic UI
    external_axis_params = _get_external_axis_params()

    axis_name = external_axis_params['Axis Name']
    axis_number = external_axis_params['Axis Number']
    driving_attribute = external_axis_params['Driving Attribute']
    position_limit_min = external_axis_params['Position Limit Min']
    position_limit_max = external_axis_params['Position Limit Max']
    velocity_limit = external_axis_params['Velocity Limit']
    attach_robot_to_external = external_axis_params['Attach']
    ingnore_in_postproc = external_axis_params['Ignore']

    # Get and check the proper controllers from viewport selection
    robot, external_axis_CTRL = _get_selection_input()

    target_CTRL = mimic_utils.get_target_ctrl_path(robot)

    # Ensure axis name is unique
    _check_external_axis_name(robot, axis_name)

    # Check that the external axis number is unique
    _check_external_axis_number(robot, axis_number)

    # If attach to robot is true, parent the robot's local control to the
    # external axis controller
    if attach_robot_to_external:
        if _check_if_robot_is_attached_to_external_axis(robot):
            raise MimicError('{} is already attached to an external ' \
                             'axis controller'.format(robot))
        _attach_robot_to_external_axis(robot, external_axis_CTRL)

    # Add attributes to robots
    # Parent Attrubute
    parent_attribute = 'externalAxis_{}'.format(axis_name)
    pm.addAttr(target_CTRL,
               longName=parent_attribute,
               niceName='External Axis: {}'.format(axis_name),
               numberOfChildren=6,
               category='externalAxis',
               attributeType='compound')
    # Define 6 children of the External Axis parent attribute
    pm.addAttr(target_CTRL,
               longName=axis_name + '_position',
               niceName='Position',
               keyable=False, attributeType='float',
               parent=parent_attribute)
    pm.addAttr(target_CTRL,
               longName=axis_name + '_axisNumber',
               niceName='Axis Number',
               keyable=False,
               attributeType='long',
               minValue=1,
               maxValue=6,
               defaultValue=1,
               parent=parent_attribute)
    pm.addAttr(target_CTRL,
               longName=axis_name + '_axisMin',
               niceName='Min',
               keyable=False,
               attributeType='float',
               parent=parent_attribute)
    pm.addAttr(target_CTRL,
               longName=axis_name + '_axisMax',
               niceName='Max',
               keyable=False,
               attributeType='float',
               parent=parent_attribute)
    pm.addAttr(target_CTRL,
               longName=axis_name + '_maxVelocity',
               niceName='Max Velocity',
               keyable=False,
               attributeType='float',
               parent=parent_attribute)
    pm.addAttr(target_CTRL,
               longName=axis_name + '_ignore',
               niceName='Ignore',
               keyable=False,
               attributeType='bool',
               parent=parent_attribute)

    # If the driving attribute is a translate attribute, we convert the user
    # input from millimeters to Maya's default unit of centimeters
    if 'translate' in driving_attribute:
        position_limit_min = position_limit_min / 10
        position_limit_max = position_limit_max / 10

    # Set all External Axis attributes accordingly
    axis_parent_attribute = target_CTRL + '.' + axis_name
    
    pm.setAttr(axis_parent_attribute + '_axisNumber', axis_number)
    
    # Try locking the axis_number attribute
    try:
        # If the robot is referenced, Maya will throw an exceptrion when it
        # tries to lock an attribute
        pm.setAttr(axis_parent_attribute + '_axisNumber', lock=True)
    except:
        pass

    pm.setAttr(axis_parent_attribute + '_axisMin', position_limit_min)
    pm.setAttr(axis_parent_attribute + '_axisMax', position_limit_max)
    pm.setAttr(axis_parent_attribute + '_maxVelocity', velocity_limit)
    pm.setAttr(axis_parent_attribute + '_ignore', ingnore_in_postproc)

    # Connect position attribute to driving attribute
    driving_attribute_name = external_axis_CTRL + '.' + driving_attribute
    destination_attribute_name = axis_parent_attribute + '_position'
    pm.connectAttr(driving_attribute_name,
                   destination_attribute_name)

    # Set the External Axis control limits
    _set_external_axis_CTRL_limits(robot,
                                   external_axis_CTRL,
                                   external_axis_params)

    # Select the robot's target/tool controller
    tool_CTRL = mimic_utils.get_tool_ctrl_path(robot)
    if pm.objExists(tool_CTRL):
        pm.select(tool_CTRL)
    else:
        pm.select(target_CTRL)

    list_axes()
    pm.headsUpMessage('External axis \'{}\' added successfully to {}'
                      .format(axis_name, robot))
Exemple #18
0
def update_external_axis(*args):
    """
    Update external axis in Mimic.
    :param args:
    :return:
    """
    # Get the selected item from the Mimic UI
    selection = pm.textScrollList('tsl_externalAxes',
                                  selectItem=True,
                                  query=True)[0]

    # Split the selection into the robot's name and the external axis name
    robot_str, axis_name = selection.split(': ')
    pm.select(robot_str)
    robot = mimic_utils.get_robot_roots()[0]

    external_axis_params = _get_external_axis_params()

    axis_number = external_axis_params['Axis Number']
    driving_attribute = external_axis_params['Driving Attribute']
    position_limit_min = external_axis_params['Position Limit Min']
    position_limit_max = external_axis_params['Position Limit Max']
    velocity_limit = external_axis_params['Velocity Limit']
    attach_robot_to_external = external_axis_params['Attach']
    ingnore_in_postproc = external_axis_params['Ignore']

    target_CTRL = mimic_utils.get_target_ctrl_path(robot)

    # Set all External Axis attributes accordingly
    axis_parent_attribute = target_CTRL + '.' + axis_name

    # Check that the external axis number is unique
    if axis_number == pm.getAttr(axis_parent_attribute + '_axisNumber'):
        pass
    else:
        _check_external_axis_number(robot, axis_number)

    # If attach to robot is true, parent the robot's local control to the
    # external axis controller
    if attach_robot_to_external:
        # Check if the robot is already attached to an external axis controller
        if _check_if_robot_is_attached_to_external_axis(robot):
            raise MimicError('{} is already attached to an external ' \
                             'axis controller'.format(robot))
        # Get and check the proper controllers from viewport selection
        _, external_axis_CTRL = _get_selection_input()
        _attach_robot_to_external_axis(robot, external_axis_CTRL)

    # Check if our driving attribute needs to be updated. If not, do nothing
    # If so, update the connection
    axis_attribute_name = target_CTRL + '.{}'.format(axis_name)
    external_axis_CTRL, old_driving_attribute = _get_external_axis_connections(axis_attribute_name)
    if old_driving_attribute == driving_attribute:
        pass
    else:
        # Connect position attribute to driving attribute
        old_driving_attribute_path = external_axis_CTRL + '.' + old_driving_attribute
        new_driving_attribute_path = external_axis_CTRL + '.' + driving_attribute
        destination_attribute_name = axis_parent_attribute + '_position'
        pm.disconnectAttr(old_driving_attribute_path, destination_attribute_name)
        pm.connectAttr(new_driving_attribute_path, destination_attribute_name)

        # Update the external axis' position/rotation limits
        # Find the original driving attribute and disable it's axis limits
        _clear_external_axis_CTRL_limits(robot,
                                         external_axis_CTRL,
                                         old_driving_attribute,
                                         axis_name)

        _set_external_axis_CTRL_limits(robot,
                                       external_axis_CTRL,
                                       external_axis_params)

    # If the driving attribute is a translate attribute, we convert the user
    # input from millimeters to Maya's default unit of centimeters
    if 'translate' in driving_attribute:
        position_limit_min = position_limit_min / 10
        position_limit_max = position_limit_max / 10

    # Set all appropriate attributes on the robot
    # If the robot is referenced, Maya will throw an exceptrion when it
    # tries to lock an attribute
    try:

        pm.setAttr(axis_parent_attribute + '_axisNumber', lock=False)
    except:
        pass

    pm.setAttr(axis_parent_attribute + '_axisNumber', axis_number)
    
    try:
        pm.setAttr(axis_parent_attribute + '_axisNumber', lock=True)
    except:
        pass

    pm.setAttr(axis_parent_attribute + '_axisMin', position_limit_min)
    pm.setAttr(axis_parent_attribute + '_axisMax', position_limit_max)
    pm.setAttr(axis_parent_attribute + '_maxVelocity', velocity_limit)
    pm.setAttr(axis_parent_attribute + '_ignore', ingnore_in_postproc)

    # Select the external axis
    pm.select(external_axis_CTRL)

    pm.headsUpMessage('{}: Axis \'{}\' successfully updated'
                      .format(robot, axis_name))
Exemple #19
0
def remove_external_axis(*args):
    """
    Removes external axis from the robot it's attached to by deleting all of
    its attributes. The axis controller and models are preserved.
    This function just breaks the connection between the robot and the axis
    :param *args: required by Maya UI
    :return:
    """

    # Get the selected item from the Mimic UI
    selection = pm.textScrollList('tsl_externalAxes',
                                  selectItem=True,
                                  query=True)[0]

    # Split the selection into the robot's name and the external axis name
    robot_str, axis_name = selection.split(': ')
    pm.select(robot_str)
    robot = mimic_utils.get_robot_roots()[0]

    target_CTRL = mimic_utils.get_target_ctrl_path(robot)

    parent_attribute = '{}.externalAxis_{}'.format(target_CTRL, axis_name)

    # Remove connections between the axis controller and the robot
    external_axis_attribute_path = target_CTRL + '.' + axis_name
    external_axis_CTRL, driving_attribute = _get_external_axis_connections(
        external_axis_attribute_path)
    driving_axis = driving_attribute[-1]
    # Prep transformation string for Maya's limit attributes
    if 'translate' in driving_attribute:
        driving_attribute_trunc = 'Trans'
    else:
        driving_attribute_trunc = 'Rot'
    _enable_external_axis_limits(external_axis_CTRL,
                                 driving_attribute_trunc,
                                 driving_axis,
                                 enable=False)

    # Delete External Axis attribute on the robot controller
    pm.deleteAttr(parent_attribute)

    # Clear the axis from the Mimic UI selection and reset the UI
    pm.textScrollList('tsl_externalAxes',
                      edit=True,
                      removeItem=selection)
    if not pm.textScrollList('tsl_externalAxes',
                             query=True,
                             numberOfItems=True):
        reset_external_axis_UI()

    '''
    # NEEDS Attention. This deletes parent constraint even if the axis
    # being removed isn't the one the robot is attached to
    if _check_if_robot_is_attached_to_external_axis(robot):
        pm.delete('{}|robot_GRP|local_CTRL|' \
                  'localCTRL_externalAxisCTRL_parentConstraint'
                  .format(robot))
        pm.setAttr('{}|robot_GRP|local_CTRL.visibility'.format(robot), 1)
    '''

    pm.select(target_CTRL)
    pm.headsUpMessage('External Axis \'{}\' removed successfully from {}'
                      .format(axis_name, robot))
Exemple #20
0
def add_io(*args):
    """
    Adds an IO to a robot based on user inputs in Mimic UI.
    :param args: required by Maya to call a function from UI button
    """
    # Get the IO's parameters from the Mimic UI
    io_params = _get_io_params()

    io_name = io_params['IO Name']
    io_number = io_params['IO Number']
    postproc_id = io_params['Postproc ID']
    io_type = io_params['Type']
    ignore_in_postproc = io_params['Ignore']

    # Get and check the proper controllers from viewport selection
    robot = _get_selection_input()

    target_CTRL = mimic_utils.get_target_ctrl_path(robot)

    # Ensure IO name is unique
    _check_io_name(robot, io_name)

    # Check that the IO number is unique
    _check_io_number(robot, io_number)

    # Establish attribute type from input Type
    if io_type == 'digital':
        attr_type = 'bool'
    else:
        attr_type = 'float'

    # Add attributes to robots
    # Parent Attrubute
    parent_attribute = 'io_{}'.format(io_name)
    pm.addAttr(target_CTRL,
               longName=parent_attribute,
               niceName='IO: {}'.format(io_name),
               numberOfChildren=4,
               category='io',
               attributeType='compound')
    # Define 4 children of the IO parent attribute
    pm.addAttr(target_CTRL,
               longName=io_name + '_value',
               niceName=io_name,
               keyable=True,
               attributeType=attr_type,
               parent=parent_attribute)
    pm.addAttr(target_CTRL,
               longName=io_name + '_postprocID',
               niceName='Postproc ID',
               keyable=False,
               dataType='string',
               parent=parent_attribute)
    pm.addAttr(target_CTRL,
               longName=io_name + '_ioNumber',
               niceName='IO Number',
               keyable=False,
               attributeType='long',
               minValue=1,
               maxValue=12,
               defaultValue=1,
               parent=parent_attribute)
    pm.addAttr(target_CTRL,
               longName=io_name + '_ignore',
               niceName='Ignore',
               keyable=False,
               attributeType='bool',
               parent=parent_attribute)

    # Set all IO attributes accordingly
    io_parent_attribute = target_CTRL + '.' + io_name

    pm.setAttr(io_parent_attribute + '_ioNumber', io_number)

    # Try locking the io_number attribute
    try:
        # If the robot is referenced, Maya will throw an exception when it
        # tries to lock an attribute
        pm.setAttr(io_parent_attribute + '_ioNumber', lock=True)
    except:
        pass

    pm.setAttr(io_parent_attribute + '_postprocID', postproc_id)
    pm.setAttr(io_parent_attribute + '_ignore', ignore_in_postproc)

    # Select the robot's target/tool controller
    tool_CTRL = mimic_utils.get_tool_ctrl_path(robot)
    if pm.objExists(tool_CTRL):
        pm.select(tool_CTRL)
    else:
        pm.select(target_CTRL)

    list_ios()
    pm.headsUpMessage('IO \'{}\' added successfully to {}'.format(
        io_name, robot))