Page MenuHome

bpy.ops.objects ignores override context
Closed, ResolvedPublic

Description

I ran

import bpy
# set selection
bpy.data.objects["Cube"].select = False
bpy.data.objects["Plane"].select = True

# override context
override = bpy.context.copy()
override["selected_bases"] = [bpy.data.scenes[0].object_bases["Cube"]]
override["active_base"] = bpy.data.scenes[0].object_bases["Cube"]

bpy.ops.object.origin_set(override)  # works on Plane
bpy.ops.transform.translate(override, value=(1,1,1))  # works on Cube

expecting to reset origin of Cube which in fact reset the Plane.

version
Blender 2.79b
ubuntu 16.04

Event Timeline

Philipp Oeser (lichtwerk) changed the task status from Unknown Status to Resolved.Nov 2 2018, 12:09 PM
Philipp Oeser (lichtwerk) claimed this task.

operator origin_set relies on selected_editable_objects afaict, so adding override["selected_editable_objects"] = [bpy.data.objects["Cube"]] should do the trick:

import bpy
# set selection
bpy.data.objects["Cube"].select = False
bpy.data.objects["Plane"].select = True

# override context
override = bpy.context.copy()
override["selected_bases"] = [bpy.data.scenes[0].object_bases["Cube"]]
override["active_base"] = bpy.data.scenes[0].object_bases["Cube"]
override["selected_editable_objects"] = [bpy.data.objects["Cube"]]

bpy.ops.object.origin_set(override)  # works on Plane
bpy.ops.transform.translate(override, value=(1,1,1))  # works on Cube