I have been trying to write a script that generates pictures of sphere packing's given positions and radii's that are publication quality. The most helpful post I found was here: https://gskielian.wordpress.com/2012/11/29/creating-a-red-sphere-in-blender-with-python/ .

From this post I have been able to generate multiple spheres in blender with different coordinates for their centers. What I haven't been able to do from this code is adjust their radii. I thought that setting the radii for a sphere would be found in this portion of the code:

red = makeMaterial(‘Red’,(1,0,0),(1,1,1),1)
origin = (0,0,0)
setMaterial(bpy.context.object, red)

But I've tried to adjust almost everything in that line of code with no use. I'm hoping that someone can help me make adjustments to the linked code such that it generates a sphere of a specific radii, thanks!


1 Answer 1


There are many ways to do this, the least complicated approach is probably this:

import bpy

properties = [
   [[-2, 0, 0], 0.2],
   [[-1, 0, 0], 0.3],
   [[+0, 0, 0], 0.4],
   [[+1, 0, 0], 0.5],
   [[+2, 0, 0], 0.6]

# [co]ordinate, and [r]adius 
for co, r in properties:
    bpy.ops.mesh.primitive_uv_sphere_add(segments=34, size=r, location=co)

enter image description here

See the documentation for UV Sphere

Depending on scene complexity other approaches will make more sense.

  • $\begingroup$ This is awesome, thank you so much for your speedy and "brain-dead" response, it is much better than the method I linked! $\endgroup$ Jan 8, 2016 at 22:54
  • $\begingroup$ @mikervdn that's quite alright, welcome to the community! $\endgroup$
    – zeffii
    Jan 8, 2016 at 22:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .