Skip to content

Instantly share code, notes, and snippets.

@CGArtPython
Created November 28, 2022 07:31
Show Gist options
  • Save CGArtPython/004d414871f04bfb2c7605a88ea1e7a7 to your computer and use it in GitHub Desktop.
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)
# 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
@kalpit3d
Copy link

kalpit3d commented Mar 29, 2025

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