DWQA QuestionsCategory: PythonBlender – Python – Object selection scripts
admin Staff asked 7 months ago

how to select a certain object in the scene and make it the active object:

ob = bpy.context.scene.objects["Cube"] # Get the object
bpy.ops.object.select_all(action='DESELECT') # Deselect all objects
bpy.context.view_layer.objects.active = ob # Make the cube the active object
ob.select_set(True) # Select the cube

how to select multiple objects by name:

for o in ("Cube", "Camera", "Light"):
obj = bpy.context.scene.objects.get(o)
if obj: obj.select_set(True)

how to select all objects of a certain collection:

col = bpy.data.collections.get("Collection")
if col:
for obj in col.objects: