Last active
May 21, 2023 18:34
-
-
Save p2or/526243d1af3fd21cd74d to your computer and use it in GitHub Desktop.
Select random Object in Group #Blender
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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