2 votes

How can I activate an object in Blender with Python

From a Python script I want to activate an object to enter the edit 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 you select the object there is another object asset at the time of entering into the edit mode with bpy.ops.object.editmode_toggle(), enters the edit mode of the object that was active previously and is not the selected object with (1).

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

I hope someone can help me, thank you for your attention. Annex Python code to run in Blender, so that you can see what I mean exactly.


import bpy

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

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



FJSevilla Points 29084

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

 import bpy

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

enter image description here


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: