Joining and Rotating objects in script

Hi. Total newb here… at least as far as both Blender and Python go…so it’s been especially sucky dealing with nuances of the Blender IDE and Python syntax simultaneously.

I am trying to create a 1x2 stack of cubes that rotates 45 degrees in each iteration in the Z axis. This is the code I have but it’s not rotating the objects…instead just stacking them straight up.

I figured the objects aren’t being joined before the rotate but can’t figure out why this isn’t working. Probably some setup that I’m not aware of but does anyone know how to this work? Many thanks :slight_smile:

import bpy

zRotor = 0.0
xCount = 1
yCount = 2
zCount = 6

for zAxis in range (zCount):

for xAxis in range (xCount):
    
    zRotor += 0.5

    for yAxis in range (yCount):
      

       
            bpy.ops.mesh.primitive_cube_add( location=(xAxis *3 , yAxis *3, zAxis * 3), scale=(1.2, 1.1, 1))
            bpy.ops.object.select_all()
            bpy.ops.object.join()
            bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME', center='MEDIAN')
     
            bpy.ops.transform.rotate(value= zRotor, orient_axis='Z', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, False, True), mirror=False, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)

stack1