3

I am doing this tutorial and try to learn how Rigid Bodies work. I have selected the center parts of the brick wall and made them active.

enter image description here

Somewhat later I want to reselect the active parts but how to do that ? How can you reselect the parts that you have made active ?

  • You could simply group them once selected the first time (ctrl+G), then use the outliner to find them again (set the search option to 'groups')... but is your question about to reselect them without having anticipated that ? – lemon Jul 31 '16 at 11:22
  • Yes, your answer is a good tip for the next time. But my question was how to reselect them without having anticipated that ? So are the "active" bodies selectable ? –  Jul 31 '16 at 11:34
  • Is your question about how to find which object does have Rigid Body physics added (assuming there are a lot of them and only several have modifier added) ? – Mr Zak Jul 31 '16 at 11:55
  • @MrZak My question is about the brick wall.Some parts are "passive" rigid body objects and other are "active" rigid body objects (the ones that get smashed). The question is how to reselect the "active" rigid body objects –  Aug 01 '16 at 12:43
  • I see now; yes, probably the most efficient and may be the only way to do that is by scripting. – Mr Zak Aug 01 '16 at 13:47
  • @MrZak OK. Batfinger created a script, but I have no Python knowledge. Don't know what piece of those scripts I should import in Blender and how to do that ? –  Aug 01 '16 at 14:27
  • @OldMan, I undelete my answer (which is in the same principle of the better one given by batFinger), just in order you see how to use the script. The difference is once you have run the script, batFinger solution give you a menu. Mine simply selects the wanted objects. Tell me if this is ok for you, then I will delete it again. – lemon Aug 01 '16 at 14:31
  • @lemon the solution of batFinger works really nice. But I am also very happy with your suggestion to use Groups next time. Where can I read more about Groups ? –  Aug 02 '16 at 08:30
  • @OldMan, surely in the documentation https://www.blender.org/manual/editors/3dview/object/relationships/groups.html. As said here, groups are only a way to organize your objects, logically (so with no impact on the other aspects) – lemon Aug 02 '16 at 08:32
  • @lemon Thanks. Do you know perhaps how I can install the batFinger script as a permanent extension of my Blender application ? I have zero Python know how –  Aug 02 '16 at 09:28
  • @OldMan, I am not sure but you may try to open a new Blender session, add the script and run it then save your startup file. Not sure it works for this script. But ask batFINGER he may know that far better than me – lemon Aug 02 '16 at 09:31

1 Answers1

5

Operator As a select physics operator.

Edit update for 2.8

enter image description here

bl_info = {
    "name": "Select RigidBody Objects",
    "author": "batFINGER",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "location": "View3D > Select > Object > Rigid Body Object",
    "description": "Selects Rigid Body Objects",
    "warning": "",
    "wiki_url": "",
    "category": "3D View",
    }


import bpy
from bpy.types import Operator
from bpy.props import EnumProperty, BoolProperty


class OBJECT_OT_select_rigid_body(Operator):
    """Select Rigid Body"""
    bl_idname = "object.select_rigid_body"
    bl_label = "Select Rigid Body Objects"
    bl_options = {'REGISTER', 'UNDO'}
    rna = bpy.ops.object.select_all.get_rna_type()
    action: EnumProperty(
        name="Action",
        items=tuple((i.identifier, i.name, i.description)
            for i in rna.properties['action'].enum_items),
        default='SELECT',
        )
    enum  = bpy.types.RigidBodyObject.bl_rna.properties['type']

    items = [(o.identifier, o.name, o.description, o.icon, o.value)
              for o in enum.enum_items]
    type: EnumProperty(items=items, name=enum.name, description=enum.description, default=enum.default)
    extend: BoolProperty(name = "Extend Selection", default=False)

    def execute(self, context):
        scene = context.scene
        obj = context.active_object

        rigids = [o for o in scene.objects if o.rigid_body
                    and o.rigid_body.type == self.type]        
        if not self.extend:
            bpy.ops.object.select_all(action='DESELECT')

        action = self.action
        if rigids:
            if action == 'SELECT':
                select = True
            if action == 'DESELECT':
                selection = False
            if action == 'INVERT':
                select = not obj.select

            if obj not in rigids and not self.extend:
                scene.objects.active = rigids[0]
            for o in rigids:           
                o.select_set(select)

        return {'FINISHED'}


# Registration

def add_select_menu(self, context):
    self.layout.operator_menu_enum(
        OBJECT_OT_select_rigid_body.bl_idname,
        "type",
        icon='PHYSICS')


def register():
    bpy.types.VIEW3D_MT_select_object.prepend(add_select_menu)
    bpy.utils.register_class(OBJECT_OT_select_rigid_body)


def unregister():
    bpy.types.VIEW3D_MT_select_object.remove(add_select_menu)
    bpy.utils.unregister_class(OBJECT_OT_select_rigid_body)

if __name__ == "__main__":
    register()

Install addon as shown here https://blender.stackexchange.com/a/1689/15543

To enable. enter image description here

Alternatively (aka old answer) A simple script to add a toggling property to the object select menu. (Avoids setting up an operator, but end up with code useful to create an op later if needed)

enter image description here Showing the checkbox on menu

If toggled from false to true will select all active type rigid bodies. The other way will deselect.

import bpy
from bpy.props import BoolProperty

def select_active_rigids(self, context):
    # deselect all
    if self.select_active_rigids:
        for o in self.objects:
            o.select = False
    rigids = [o for o in self.objects if o.rigid_body
                and o.rigid_body.type == 'ACTIVE']
    for o in rigids:
        self.objects.active = o
        o.select = self.select_active_rigids
    return None

bpy.types.Scene.select_active_rigids = BoolProperty(update=select_active_rigids)    

def draw(self, context):
    scene = context.scene
    layout = self.layout
    text = "Deselect" if scene.select_active_rigids else "Select"

    layout.prop(scene, "select_active_rigids",
                text="%s Rigids" % text,
                toggle=True)   

# hit F8 to clear from menu (reloads all)
bpy.types.VIEW3D_MT_select_object.prepend(draw)

For scripters: an example of defining a context property.

import bpy
def selected_active_physics_objects(self):
    return [o for o in self.selected_objects
                if o.rigid_body
                    and o.rigid_body.type == 'ACTIVE']

bpy.types.Context.selected_active_physics_objects = property(selected_active_physics_objects)

'''
Example Console Output
>>> C.selected_active_physics_objects
[bpy.data.objects['Cone.001'], bpy.data.objects['Cone'], bpy.data.objects['Cube.001'], bpy.data.objects['Cube']]
'''
batFINGER
  • 84,216
  • 10
  • 108
  • 233