0

I'm trying to add a simple triangle to a scene (with Blender demo BMW) using python script. I then want to enter edit mode, select a vertex and then move 3D cursor to that vertex, exit edit mode and then add an area light at the 3D cursor. Repeat to set up very basic three-point lighting. However, when I deselect all objects, and then try to select my "LightingRig" object using the code example, I can see that the triangle is active (not selected, as intended) and I get the following error:

RuntimeError: Operator bpy.ops.object.mode_set.poll() Context missing active object

How can I set the triangle to be selected, and not active?enter image description here

import bpy
import os
import sys
bpy.ops.wm.append(
    filepath=os.path.join(lr_file_path, inner_path, lr_object_name),
    directory=os.path.join(lr_file_path, inner_path),
    filename=lr_object_name
)
lr = bpy.data.objects.get("LightingRig")

bpy.ops.object.select_all(action='DESELECT')

lr.select_set(state=True) bpy.ops.object.mode_set(mode="EDIT") # This is where the error occurs

0 Answers0