0
$\begingroup$

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:
   print(bpy.context.object.scale[0])

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.

$\endgroup$

1 Answer 1

5
$\begingroup$

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])

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .