Esempio n. 1
0
 def poll(cls, context):
     bbones = ('bbone', 'bbone_start', 'bbone_end', 'bbone_head',
               'bbone_in', 'bbone_out')
     if context.selected_pose_bones:
         for bone in context.selected_pose_bones:
             if Is.linked(bone):
                 continue
             for bb in bbones:
                 if get_name(bone, bb) in bone.id_data.pose.bones:
                     return True
Esempio n. 2
0
def get_rig_bones(context):
    rigs = dict()  # rig object with a list of selected and mirrored bones
    selected = list()  # remember selected and non-selected mirror bones

    for bone in context.selected_pose_bones:
        rig = bone.id_data
        if Is.linked(rig):
            continue
        if rig not in rigs:
            rigs[rig] = list()

        if (bone not in rigs[rig]):
            rigs[rig].append(bone)
            selected.append((bone, rig))
            if (rig.pose.use_mirror_x or rig.data.use_mirror_x):
                mirror = Get.mirror_bone(bone)
                if mirror and (mirror not in rigs[rig]):
                    rigs[rig].append(mirror)
                    selected.append((mirror, rig))

    return (rigs, selected)
Esempio n. 3
0
File: Set.py Progetto: Irmitya/zpy
def mode(context, mode, target=None, keep_visiblity=True):
    """
    Set the context.mode for an object (or bone's rig)
    """
    if not target:
        bpy.ops.object.mode_set(mode=mode)
        return context.mode == mode

    target = target.id_data
    # I can't think of a situation where I care to use
    # a bone/etc instead of the object

    # objects = context.selected_objects
    # for obj in objects:
    # select(obj, False)

    if Is.linked(target) and mode not in ('OBJECT', 'POSE'):
        return False

    class active_item:
        mode = target.mode
        is_visible = Set.visible(context, target, True)

    if mode != target.mode:
        modes = dict()
        selected = list()
        objects = list()

        # Find the visible objects of the same type as the target object
        # Remember their modes and selection, then deselect them
        for obj in Get.in_view(context):
            if obj == target or obj.type != target.type or not Is.visible(
                    context, obj):
                continue
            if obj.mode not in modes:
                modes[obj.mode] = list()
            modes[obj.mode].append(obj)

            if Is.selected(obj):
                selected.append(obj)
            Set.select(obj, False)
            objects.append(obj)

        # Remember the target's selected status
        pselect = Is.selected(target)

        # Set the mode for the target object
        previous = Set.active(context, target)
        Set.select(target, False)
        bpy.ops.object.mode_set(mode=mode)

        # Since the operator switches all objects to the specified mode
        # Go through the objects and manually set them back their previous mode
        for pmode in modes:
            for obj in modes[pmode]:
                Set.select(obj, True)
            Set.active(context, obj)
            bpy.ops.object.mode_set(mode=pmode)
            Set.active(context, None)
            for obj in modes[pmode]:
                Set.select(obj, False)

        # Re-select previously selected objects
        for obj in selected:
            Set.select(obj, True)

        # reselect target if it was selected
        Set.select(target, pselect)

        # Set the active object back to the original
        if previous is not None:
            Set.active(context, previous)
        else:
            Set.active(context, target)

    if (keep_visiblity):
        Set.visible(context, target, active_item.is_visible)

    # for obj in objects:
    # select(obj, True)

    return (target.mode == mode)
Esempio n. 4
0
 def poll(cls, context):
     if context.selected_pose_bones:
         for bone in context.selected_pose_bones:
             if not Is.linked(bone):
                 return True