OK, from the selected objects, I need to join one selected object with the active object and execute some other code. Then from the others select the next selected object and then execute the code again. I thought the following would work ,but it does all at the same.
import bpy SEL_OBJS = bpy.context.selected_objects ACT_OBJ = bpy.context.active_object #Join one at a time and execute more code for OBJS in SEL_OBJS: bpy.ops.object.join() #More code here
Got my code working with the following.
import bpy SEL_OBJS = bpy.context.selected_objects ACT_OBJ = bpy.context.active_object #List of all objects but the active object SEL_NO_ACT = [o for o in SEL_OBJS if ACT_OBJ != o] #Deselect list objects for OBJS in SEL_NO_ACT: OBJS.select_set(state=False) #Loop list objects while len(SEL_NO_ACT) >= 1: OBJS = SEL_NO_ACT.pop() OBJS.select_set(state=True) bpy.ops.object.join() #Run code for each object after joining