2

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

Lev
  • 45
  • 2
  • 4
  • Can't you just select them all and hit Ctrl+J in Object Mode? – Cubit Dec 20 '15 at 13:04
  • Yes I can, but it will take a very long time , about an hour for one scene , such scenes have a lot of – Lev Dec 20 '15 at 13:06
  • I work in the project company , and we are developing a 3D model of the plant , import the model into a blender , and ultimately have a huge number of objects and groups , only about 10,000 teams and 600,000 objects – Lev Dec 20 '15 at 13:09

1 Answers1

4

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[0]
    bpy.context.scene.objects.active = joiner
    bpy.ops.object.join()

    # deselect everything before the next iteration
    bpy.ops.object.select_all(action='DESELECT')
zeffii
  • 39,634
  • 9
  • 103
  • 186