My problem is that I have a scene with many objects , which are grouped into EMPTY, I need to take all of the objects in the parent (EMPTY) and unite them into a single object , if you do it manually, it takes a lot of time
Here's the pseudo code:
make sure nothing is selected to start off. for every empty that has children: 1. select all children of the empty 2. set first child to active_object (or any child) 3. invoke a bpy.ops.join 4. deselect everything
Because you can't join anything to an Empty, You have to programmatically set a Mesh Object to be the Active Object then join other selected mesh objects to it.
Here's the python:
import bpy # get the list of empties that have children empties = [e for e in bpy.data.objects if e.type == 'EMPTY' and e.children] # we need to deselect everything first bpy.ops.object.select_all(action='DESELECT') for empty in empties: for obj in empty.children: obj.select = True joiner = empty.children bpy.context.scene.objects.active = joiner bpy.ops.object.join() # deselect everything before the next iteration bpy.ops.object.select_all(action='DESELECT')