How to set object in such a situation

I have such a situation

Cube is active object and Sphere have secondary selection ? I don’t know how to properly name this type of selection.
Is there a possibility to write a script in Blender Python, that Sphere will be a active object, and Cube will be deselect ? Of course I know how to set active object by name but I don’t know what to do in that case.
Greets :slight_smile:

How do you choose which object you want to be active? By name? Will there only ever be two objects selected?

Selected objects: bpy.context.selected_objects
Active object: bpy.context.active_object

Assign some object to a variable by name: someObjectHere =['Grid']

Set an active object: = someObjectHere
Deselect an object: someObjectHere.select_set(False)

If there are only ever two selected you could do something like:

import bpy

ctx = bpy.context
active = ctx.active_object
selected = ctx.selected_objects

# Get the other object that isn't active
myObject = [obj for obj in selected if obj != active][0]

active.select_set(False) = myObject
1 Like

Thank You very much. Know I understand how It’s works in Blender.
One more time thanks for help