Skip to content

Instantly share code, notes, and snippets.

@Andrej730
Created June 4, 2023 19:24
Show Gist options
  • Save Andrej730/98480e06d75a7df4a65477906d57cbc6 to your computer and use it in GitHub Desktop.
Save Andrej730/98480e06d75a7df4a65477906d57cbc6 to your computer and use it in GitHub Desktop.
random_object_colors operator for blender
bl_info = {
"name": "Random Object Colors",
"author": "@Andrej730",
"version": (1, 0),
"blender": (2, 90, 0),
"location": "F3 -> Random Object Color",
"description": "",
"warning": "",
"category": "Objects"
}
import bpy
import random
class RandomObjectColor(bpy.types.Operator):
bl_idname = "object.random_object_color"
bl_label = "Random Object Color"
bl_description = "Randomize object color"
def execute(self, context):
objects = context.selected_objects + [context.active_object]
objects = set(objects)
for obj in objects:
obj.color = self.get_random_color()
return {'FINISHED'}
def get_random_color(self):
''' generate rgb using a list comprehension '''
r, g, b = [random.random() for i in range(3)]
return r, g, b, 1
def register():
bpy.utils.register_class(RandomObjectColor)
def unregister():
bpy.utils.unregister_class(RandomObjectColor)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment