3
$\begingroup$

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 ?

$\endgroup$
11
  • $\begingroup$ 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 ? $\endgroup$
    – lemon
    Commented Jul 31, 2016 at 11:22
  • $\begingroup$ 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 ? $\endgroup$
    – user13877
    Commented Jul 31, 2016 at 11:34
  • $\begingroup$ 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) ? $\endgroup$
    – Mr Zak
    Commented Jul 31, 2016 at 11:55
  • $\begingroup$ @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 $\endgroup$
    – user13877
    Commented Aug 1, 2016 at 12:43
  • $\begingroup$ I see now; yes, probably the most efficient and may be the only way to do that is by scripting. $\endgroup$
    – Mr Zak
    Commented Aug 1, 2016 at 13:47

1 Answer 1

5
+50
$\begingroup$

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']]
'''
$\endgroup$
0

You must log in to answer this question.