Created
          November 28, 2022 07:31 
        
      - 
      
- 
        Save CGArtPython/004d414871f04bfb2c7605a88ea1e7a7 to your computer and use it in GitHub Desktop. 
    Final code for a Beginner Blender Python Tutorial about using a for/while loop (link to tutorial: https://youtu.be/AcoYA4T2ErU)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # give Python access to Blender's functionality | |
| import bpy | |
| # extend Python's math functionality | |
| import math | |
| # add a cube mesh into the scene | |
| bpy.ops.mesh.primitive_cube_add() | |
| # get a reference to the currently active object | |
| obj = bpy.context.active_object | |
| # scale the cube mesh | |
| obj.scale.x = obj.scale.x * 0.5 | |
| obj.scale.y = obj.scale.y * 2 | |
| obj.scale.z = obj.scale.z * 0.1 | |
| # apply the scale | |
| bpy.ops.object.transform_apply() | |
| # create variables for stacking and rotating | |
| angle_step = 3 | |
| current_angle = angle_step | |
| # stack and rotate the mesh | |
| while current_angle <= 360: | |
| # duplicate the mesh | |
| bpy.ops.object.duplicate(linked=True) | |
| # get a reference to the currently active object | |
| obj = bpy.context.active_object | |
| # update the location of the object on the Z axis | |
| obj.location.z += obj.dimensions.z | |
| # update the rotation | |
| obj.rotation_euler.z = math.radians(current_angle) | |
| # update the angle for the next iteration | |
| current_angle += angle_step | 
bpy.ops.object.duplicate_linked()
#duplicate current object
I  found the issue, maybe syntax of Blender 4.4 is different
i replace duplicate_linked() with duplicate(linked=true)
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
#below is my code, it run succesfully but for loop is not working
import bpy
import math
bpy.ops.mesh.primitive_cube_add(size = 1)
#adding a cube
obj=bpy.context.active_object
#assign object container to hold added cube
obj.scale.z *= 0.1
obj.scale.y *= 0.2
#scaling the 'obj' object
bpy.ops.object.transform_apply( scale=True, location=False, rotation=False)
#appling all tranform
angle_step = 3
current_angle = angle_step
count = int(360 / angle_step)
#declaring input and operation variable
for i in range(count):