[EMS Discuss] Python scripts and Blender

John Burridge burridge.john at gmail.com
Fri Apr 20 22:04:11 PDT 2012


Here's another Python script.  It uses sin and cos functions to place
meshes onto a sphere... I'm not sure why I'm not using divisions of pi
in it, but it works.

==============

# Nov-23 2010
# Script to make a cloud of mesh items (in this case cubes)
#

import bpy   # You have to import bpy calls or you can't script primitives
import math # You have to import cmath calls to do sine and cosine functions

#
# phi should be the XY plane, theta should be the YZ plane
#
theta = phi = x = y = z = 0   #  defining x y and z by assigning a value
step = 1  # 1 = really smooth shapes. Larger numbers give chunkier shapes
lobe = 5  # fiddle with lobes to get different patterns. 5 gives star
patterns.  .33333 gives a cool loop.

while theta < 360:
    x = 10 * math.cos(theta) * math.sin(phi)
    y = 10* math.sin(theta) * math.sin(phi)
    z = 10 * math.cos(phi)
    bpy.ops.mesh.primitive_cube_add(view_align=False,
enter_editmode=False, location=(x, y, z), rotation=(phi, 0.0, theta))
    phi = phi + (step * lobe)
    theta = theta + step

==============================


-- 
----

John Burridge
burridge.john at gmail.com
http://johnburridge.blogspot.com


More information about the Discuss mailing list