2
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Can't you just select them all and hit Ctrl+J in Object Mode? $\endgroup$ – Cubit Dec 20 '15 at 13:04
  • $\begingroup$ Yes I can, but it will take a very long time , about an hour for one scene , such scenes have a lot of $\endgroup$ – Lev Dec 20 '15 at 13:06
  • $\begingroup$ 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 $\endgroup$ – Lev Dec 20 '15 at 13:09
5
$\begingroup$

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')
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.