I wrote a short script which performs multiple operations on a selected objects, and some of those operations depend on the objects position. I have 100+ identical objects in different positions and I would like to apply this set of operations on each object. If I select all of the objects, is there a way to then iterate through each of the objects in this selection?
Apologies if this is a bit vague, I am fairly new to coding so I hope I am using the correct terminology. I was thinking perhaps all the selected objects could be put into an array and each one could be selected by incrementing the array index after performing all the operations.
Edit: For example
def execute(self, context):
for object in bpy.context.selected_objects:
bpy.context.scene.objects.active = object #was missing this part
bpy.ops.object.convert(target='MESH')
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.edge_face_add()
bpy.ops.object.editmode_toggle()
bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')
bpy.ops.object.editmode_toggle()
bpy.ops.view3d.snap_cursor_to_selected()
bpy.context.space_data.pivot_point = 'CURSOR'
bpy.ops.object.editmode_toggle()
return {'FINISHED'}
This seems to only apply to the last object selected even though multiple objects are highlighted.
Update: I was missing "bpy.context.scene.objects.active = object". Adding that at the start of the loops fixes the problem.