I'm making a script which places the selected objects in a row, so I need to loop through all selected objects and move them in an axis by the same offset relative to the last one. All objects start off in the same place, say 0,0,0.
I have these constants:
rowLength = 5
objectNumber = 0
horiOffsetAmount = 0.1
So say I have 3 objects, the first object stays in the same place:
bpy.context.object.location[1] = objectNumber*HoriOffsetAmount
(0*0.1 = 0)
Then I want to set the object number for the next object to be 1 greater
objectNumber = objectNumber + 1
But how do I actually make this work? At the moment it just offsets the active object, so I need to go through all the selected objects, making each one active in turn, then doing the offset, how do I do this?
Here is my current code:
import bpy
context = bpy.context
scene = context.scene
rowLength = 5
objectNumber = 0
horiOffsetAmount = 0.1
if objectNumber < rowLength:
for obj in context.selected_objects:
bpy.context.object.location[1] = horiOffsetAmount*objectNumber
objectNumber = objectNumber + 1
So the problem is is that this is only affecting the active object, but I want it to go through so object 1 is offset by 0, object 2 is offset by horiOffsetAmount
, object 3 is offset by horiOffsetAmount*2
, object 4 is offset by horiOffsetAmount*3
etc....
bpy.context.object.location[1] = horiO,,,
should beobj.location.y = horiO...
(or location[1] is cool) All the objects in context.selected_objects are selected (obj.select is True) only one is "active" ie the context.object or context.active_object $\endgroup$