0
$\begingroup$

When I run this code:

import bpy

# Select all and only meshes.
item = 'MESH'
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type=item)

# List of all known subcontexts.
subcontexts_list = ['INVOKE_DEFAULT', 'INVOKE_REGION_WIN', 'INVOKE_REGION_CHANNELS',
                    'INVOKE_REGION_PREVIEW', 'INVOKE_AREA', 'INVOKE_SCREEN',
                    'EXEC_DEFAULT', 'EXEC_REGION_WIN', 'EXEC_REGION_CHANNELS',
                    'EXEC_REGION_PREVIEW', 'EXEC_AREA', 'EXEC_SCREEN']

# Try to join using each subcontext.
for sub_context in subcontexts_list:
    try:
        bpy.ops.object.join(sub_context)

    except Exception as e:
        print('{}: {}'.format(sub_context, e))

I get these errors:

INVOKE_DEFAULT: Operator bpy.ops.object.join.poll() failed, context is incorrect
INVOKE_REGION_WIN: Operator bpy.ops.object.join.poll() failed, context is incorrect
INVOKE_REGION_CHANNELS: Operator bpy.ops.object.join.poll() failed, context is incorrect
INVOKE_REGION_PREVIEW: Operator bpy.ops.object.join.poll() failed, context is incorrect
INVOKE_AREA: Operator bpy.ops.object.join.poll() failed, context is incorrect
INVOKE_SCREEN: Operator bpy.ops.object.join.poll() failed, context is incorrect
EXEC_DEFAULT: Operator bpy.ops.object.join.poll() failed, context is incorrect
EXEC_REGION_WIN: Operator bpy.ops.object.join.poll() failed, context is incorrect
EXEC_REGION_CHANNELS: Operator bpy.ops.object.join.poll() failed, context is incorrect
EXEC_REGION_PREVIEW: Operator bpy.ops.object.join.poll() failed, context is incorrect
EXEC_AREA: Operator bpy.ops.object.join.poll() failed, context is incorrect
EXEC_SCREEN: Operator bpy.ops.object.join.poll() failed, context is incorrect

What am I doing wrong?

$\endgroup$
1
$\begingroup$

Make sure one of your mesh objects is active. You will get that error if you try to join without one being active.

This works with 2.80

import bpy

#Deselect all
bpy.ops.object.select_all(action='DESELECT')

#Mesh objects
MSH_OBJS = [m for m in bpy.context.scene.objects if m.type == 'MESH']

for OBJS in MSH_OBJS:
    #Select all mesh objects
    OBJS.select_set(state=True)

    #Makes one active
    bpy.context.view_layer.objects.active = OBJS

#Joins objects
bpy.ops.object.join()
$\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.