Skip to main content
deleted 37 characters in body
Source Link
Marty Fouts
  • 33.3k
  • 10
  • 36
  • 79
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)
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)

enter image description herescreenshot showing problems

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)

enter image description here

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)

screenshot showing problems

Source Link

Joining & Rotating objects created in code through loop

I'm a Blender & Python newb, so the nuances haven't been all that enjoyable :)

I'm trying to create a 1x2 stack of cubes that joins and rotates each layer by 45 degrees. Below is the code I have, which isn't working. The code as shown will create an aligned stack of cubes (like center example in pic). If I comment the code for joining/rotating the object then it will rotate each object individually (like left example in pic, not what I want).

I would like for each layer of 2 cubes to be joined with object mass center as origin, as in the right-most example in the pic.

Why isn't this working?

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)

enter image description here