Operator
As a select physics operator.
Edit update for 2.8
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.
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)
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']]
'''