Code for 3d monkey
if __name__ == '__main__':
# Delete all objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
main_object = create_monkey()
yellow_rgba = (1.00, 1.00, 0.00, 1.00)
mat = bpy.data.materials.new(name='yellow')
mat.use_nodes = True
mat.diffuse_color = yellow_rgba
nodes = mat.node_tree.nodes
nodes.clear()
node_material_output = nodes.new(type='ShaderNodeOutputMaterial')
node_diffuse = nodes.new(type='ShaderNodeBsdfDiffuse')
node_diffuse.name = 'Yellow Diffuse'
node_diffuse.inputs['Color'].default_value = yellow_rgba
input = node_material_output.inputs['Surface']
output = node_diffuse.outputs['BSDF']
mat.node_tree.links.new(input, output)
main_object = bpy.context.active_object
main_object.active_material = mat
set_smooth(main_object, level=5)
add_light(location=(5.00, -7.50, 5.00))
bpy.ops.object.camera_add(location=(0.00, -5.00, 0.00))
main_camera = bpy.context.object
bpy.context.scene.camera = main_camera
focal_point = create_focal_point(main_object.location)
set_focal_point(main_camera, focal_point)
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.cycles.samples = 50
bpy.context.scene.render.tile_x = 256
bpy.context.scene.render.tile_y = 256
bpy.context.scene.render.resolution_x = 600
bpy.context.scene.render.resolution_y = 600
bpy.context.scene.render.resolution_percentage = 100
bpy.context.scene.render.image_settings.compression = 100
base_filename = time.strftime('%Y %m %d - %H %M %S - ') + os.path.basename(__file__)
base_filename_no_extension = os.path.splitext(base_filename)[0]
shutil.copy(__file__, base_filename)
bpy.ops.wm.save_as_mainfile(filepath=base_filename_no_extension+'.blend')
bpy.context.scene.render.filepath = base_filename_no_extension+'.png'
bpy.ops.render.render(write_still=True)