Last active
May 21, 2023 19:14
-
-
Save p2or/87fc80a85f958bce64861211b0751e55 to your computer and use it in GitHub Desktop.
Groups by materials #Blender
This file contains 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 | |
data = {} | |
for obj in bpy.data.objects: # bpy.context.selected_objects | |
mat_slots = obj.material_slots.keys() | |
if mat_slots: | |
data_key = "-".join(mat_slots) | |
else: | |
data_key = "None" | |
data.setdefault(data_key, []).append(obj) | |
for key, value in data.items(): | |
group_name = "{}".format(key) | |
if group_name not in bpy.data.groups: | |
bpy.ops.group.create(name=group_name) | |
grp = bpy.data.groups.get(group_name) | |
for obj in value: | |
if len(obj.users_group) == 0: | |
grp.objects.link(obj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment