2
$\begingroup$

How can I join all objects in a collection? This is what i have so far:

def final():
    Coll=bpy.data.collections['low']
    #finalColl=bpy.data.collections['final']
    for obj in Coll.objects:
        if obj.type=='MESH':
           ob.join
$\endgroup$
0

1 Answer 1

1
$\begingroup$

You have to make sure you have selected all the objects you want to join using obj.select_set(True) in the for loop and make sure one of the objects is active (yellow outline). Then you can join them using bpy.ops.object.join() after the loop has finished.

import bpy

def final():
        bpy.ops.object.select_all(action='DESELECT')

        Coll = bpy.data.collections['low']
        for obj in Coll.objects:
            if obj.type == 'MESH':
               obj.select_set(True)
        #bpy.context.view_layer.objects.active = bpy.data.objects["Cube"]
        bpy.ops.object.join()

final()
$\endgroup$
2
  • 1
    $\begingroup$ Thank you! I've hear bpy.ops isn't the mos performant way to do things. is there a method that just uses python? $\endgroup$
    – zakattic
    Commented Jul 1, 2022 at 10:41
  • $\begingroup$ nope. in this case bpy.ops is the way to go. $\endgroup$
    – Harry McKenzie
    Commented Jul 1, 2022 at 11:03

Not the answer you're looking for? Browse other questions tagged .