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()
# 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
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.
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?
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?