If there is name of object in context.scene.objects

Hello!
I want make such a think.
If I have at scene selected object with name for example Cube_test then I’m making some operations.
also I want make some operation when there is object with name Cube_test2, but operation are only when object is selected.
I wrote some like that.

        for ob in bpy.context.scene.objects:
            if "Cube_test" in ob.name:
                bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=3)
            else:
                bpy.ops.object.mode_set(mode='SCULPT')

But It’s not working.
Can anyone write me, what I’m doing wrong ?

Greets and thank You for help :slight_smile:

You do not even need the for loop:

if (bpy.context.active_object.name =="Cube_test"):
    bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=3)
else:
    bpy.ops.object.mode_set(mode='SCULPT')
1 Like

Thank You for help. Also I madesuch a think

       for obj in bpy.context.selected_objects:
           if "Cube_test" in obj.name:
                
           bpy.data.objects['Cube_test'].select_set(True)

And is also working. One more time thanks
Greets

1 Like