Skip to content

Instantly share code, notes, and snippets.

@p2or
Last active May 21, 2023 18:34
Show Gist options
  • Save p2or/526243d1af3fd21cd74d to your computer and use it in GitHub Desktop.
Save p2or/526243d1af3fd21cd74d to your computer and use it in GitHub Desktop.
Select random Object in Group #Blender
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment