How can I activate an object in Blender with Python


From a Python script I want to activate an object in order to enter editing mode and edit it. To select the desired object I use

bpy.context.scene.objects["Nombre_objeto"].select = True  # (1)

What happens is that if before selecting the object another active object exists, when entering edit mode with bpy.ops.object.editmode_toggle() , it enters the editing mode of the object that was previously active and not the object selected with ( 1).

I would like to know how I can leave an active object to edit its properties.

I hope someone can help me, thanks for the attention given. Annex Python code to run in Blender, so you can see what I mean exactly.


import bpy

bpy.ops.mesh.primitive_uv_sphere_add(size=1, location=(-1,-2,0))
nombre = 'c1' = nombre[nombre].location=(1, 2, 0)

bpy.context.scene.objects["Esfera"].select = True

asked by Luis Gutiérrez 30.04.2018 в 18:55

1 answer


You must mark the selected object as active in that scene using the attribute. active of SceneObjects :

import bpy

bpy.context.scene.objects["Sphere"].select = True =['Sphere']

answered by 30.04.2018 в 19:23