import bpy import bmesh bpyscene = bpy.context.scene # Create an empty mesh and the object. mesh = bpy.data.meshes.new('Basic_Sphere') basic_sphere = bpy.data.objects.new("Basic_Sphere", mesh) # Add the object into the scene. bpyscene.objects.link(basic_sphere) bpyscene.objects.active = basic_sphere basic_sphere.select = True # Construct the bmesh sphere and assign it to the blender mesh. bm = bmesh.new() bmesh.ops.create_uvsphere(bm, u_segments=32, v_segments=16, diameter=1) bm.to_mesh(mesh) bm.free() bpy.ops.object.modifier_add(type='SUBSURF') bpy.ops.object.shade_smooth()
In this case you need keyword arguments for all but the first, meaning you need to specify the argument name like
u_segments=. The first argument is a positional argument, you only need to give the value
bm. How do I know that? Because the Blender API Documentation is not very precise here, Blender told me in the Error message "bmesh operators expect a single BMesh positional argument, all other args must be keyword".
v_segments control the initial subdivision of the mesh.
diameter is the sphere size in local coordinate system (object transforation comes on top).
matrix can be used if you want to shear, scale, rotate or move the sphere in one step.
calc_uvs is about UV maps, but don't ask me what exactly.