I am trying to write a simple code that should perform the same action on all selected objects in Blender. For example, let's assume that I have two MESH objects in my scene and I want to print the scale along the x-axis of these two "MESH" objects. Here the code:

import bpy
objects = bpy.context.scene.objects
for obj in objects:
   obj.select_set(obj.type == "MESH")
selected_objects = bpy.context.selected_objects
for cube in selected_objects:

The problem is that the code prints twice the same value, which refers to the last selected object (the one with the light yellow border). I can't understand why.


As you noticed, bpy.context.object points to the active object, regardless of the variable in your for loop.

In your last line you are iterating over all selected objects, but you are not actually using the iteration variable afterwards, cube.

Replace the last line with print(cube.scale[0])


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.