I started working on Blender scripting two years ago with a view to creating model submarine parts.

But I’d forgotten how to get started, so I just watched a simple tutorial to help refresh my memory.

Here’s the code to produce the monkeys.

import bpy

from random import randint

# Clear the workspace
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)


# Generate some randomly spaced monkeys
for _ in range( 0, 400 ):
    
    # Pick a random location within a given space
    x = randint( -20, +20 )
    y = randint( -20, +20 )
    z = randint( -10, +10 )

    # Add a monkey
    bpy.ops.mesh.primitive_monkey_add( location = ( x, y, z ) )
    
    # Change the resolution of the current monkey.
    # Shade smoothing reduces the number of vertices and thus the
    # load on the processor.
    bpy.ops.object.modifier_add( type='SUBSURF' )
    bpy.context.object.modifiers[ "Subdivision" ].levels = 2
    bpy.context.object.modifiers[ "Subdivision" ].render_levels = 1
    bpy.ops.object.shade_smooth()