I'm trying to write a Python script that parses through the outliner to join meshes that have a hierarchy. Similar to the manual option to right-click an object in the outliner, do a "Select Hierarchy" and then do a CTRL-J to join the selected.
This is what I have so far, but I think I'm lacking API knowledge to get it right:
import bpy
scene = bpy.context.scene
print("#################### JOIN HIERARCHIES ###################")
bpy.ops.object.select_all(action='DESELECT') # Deselecting all
bpy.context.area.type = 'OUTLINER'
for ob in scene.objects:
#scene.objects.active = ob
#print("--", ob.name)
if ob.type == 'MESH':
bpy.ops.outliner.object_operation(type='SELECT_HIERARCHY')
bpy.ops.object.join()
bpy.ops.object.select_all(action='DESELECT') # Deselecting all
print("################## END JOIN HIERARCHIES #################")
Thanks in advance for your help!