Joining Objects

I’m having trouble joining objects via a script in 2.57b.

My first attempt was to do this:

# switch to object mode and deselect all
    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
    bpy.ops.object.select_all(action="DESELECT")

    # if selected, combine meshes into a single mesh
    if (combineMeshes):
        for one_object in mesh_objects:
            one_object.select = True
            bpy.ops.object.join()

After that, I tried borrowing the meshmerge function from the official Unreal import/export script at https://svn.blender.org/svnroot/bf-extensions/trunk/py/scripts/addons/io_export_unreal_psk_psa.py

    # switch to object mode and deselect all
    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
    bpy.ops.object.select_all(action="DESELECT")

    # if selected, combine meshes into a single mesh
    if (combineMeshes):
        meshmerge(mesh_objects)

In both cases, I get no error, but just end up with all objects selected, but not joined. If, after the script runs, I select Join from the menu (which tooltips to bpy.ops.object.join()) it works, but nothing I do seems to be able to get the join to work from script.

Anyone have any idea what I might be doing wrong? TIA

Jeff

Looks like you’re missing a couple of steps, but that may just be my not understanding your code snippet.

First, select the objects you want to join (don’t do join in loop); then do the join operation.

In my case, I add meshes, set them as selected, and at end of operation use join to combine the created meshes. The join will use the “name” of the last selected mesh/object.

Thanks for the help. Unfortunately, I originally had the join outside the loop. I moved it into the loop as part of my debugging experimentation. It doesn’t make a difference to the result whether it’s in the loop or after the loop. :frowning:

Is adding a mesh to the selected objects a matter of doing

one_object.select = True

, or is there an operation I should be using instead to select the meshes?

Thanks much!

I tried selecting all meshes and join still failed. It doesn’t look like I have an active object, only selected objects. Could that be the problem? How do you make an object active?

I’ve had luck with this:

bpy.context.scene.objects.active=bpy.data.objects["make_active"]

Thank you. That worked! (though I had to add context between bpy and scene)

haha sorry for the typo!
glad it did