Beispiel #1
0
 def poll(cls, context):
     if context.mode == 'OBJECT':
         for o in context.selected_objects:
             if o and o.type == 'MESH':
                 return True
     elif context.mode == 'EDIT_MESH':
         for o in Get.in_view(context):
             if o and o.type == 'MESH' and o.mode == 'EDIT':
                 return True
Beispiel #2
0
    def execute(self, context):
        if context.mode == 'OBJECT':
            for o in Get.selected_objects(context):
                if o.type == 'MESH':
                    if fromWidgetFindBone(o):
                        returnToArmature(context, o)
                    # else:
                    # self.report({'INFO'}, 'Object is not a bone widget' + repr(o))
        else:
            for o in Get.in_view(context):
                if o.type == 'MESH' and o.mode == 'EDIT':
                    if fromWidgetFindBone(o):
                        returnToArmature(context, o)

        return {'FINISHED'}
Beispiel #3
0
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)