p2or
11/27/2014 - 6:06 PM

blender-selectRandomObjectInGroup

blender-selectRandomObjectInGroup

import bpy
from random import choice

scene = bpy.context.scene
ob = bpy.context.object

random_group = choice(ob.users_group)
obs = random_group.objects[:]
obs.remove(ob)

try:
    random_ob = choice(obs)
except IndexError:
    # no other object in chosen group
    pass

#bpy.ops.object.select_all(action='DESELECT')
for ob in scene.objects:
    ob.select = False
random_ob.select = True
bpy.context.scene.objects.active = random_ob