Please invest time into researching about the Blender API and Python interface, before asking questions!
image = bpy.ops.mesh.primitive_cube_add(radius=1, location = (0,0,0))
This line does not make any sense at all. primitive_cube_add is an operation, which returns a status set. In this case it returns {FINISHED}. {FINISHED} is most definitely not a python object with a save_render method.
To tackle the problem requires several steps.
- Avoid using ops.
- Create the cube.
- Avoid using ops.
- Create a camera, only cameras can render images.
- Avoid using ops.
- Create a light, otherwise your unlit cube is going to be black.
- Render an image (this can only by done with
bpy.ops).
First import the necessary modules. Store the current scene inside a variable, that way we can access it later on.
import bpy
import mathutils
scene = bpy.context.scene
A method for creating the cube is found here. I have blatantly copied it. We will have to import the bmesh module.
# Create the cube
mesh = bpy.data.meshes.new('cube')
ob = bpy.data.objects.new('cube', mesh)
scene.objects.link(ob)
import bmesh
bm = bmesh.new()
bmesh.ops.create_cube(bm, size=1.0)
bm.to_mesh(mesh)
bm.free()
Creating the light need a lamp data-block and an object block as well. light.location changes the position of the lamp object. If it is at (0, 0, 0), it will not affect the result, because it will be stuck inside the cube.
# Create a light
light_data = bpy.data.lamps.new('light', type='POINT')
light = bpy.data.objects.new('light', light_data)
scene.objects.link(light)
light.location = mathutils.Vector((3, -4.2, 5))
The camera has to be repositioned and reoriented.
# Create the camera
cam_data = bpy.data.cameras.new('camera')
cam = bpy.data.objects.new('camera', cam_data)
scene.objects.link(cam)
scene.camera = cam
cam.location = mathutils.Vector((6, -3, 5))
cam.rotation_euler = mathutils.Euler((0.9, 0.0, 1.1))
Set the render settings of the current scene, and render it. write_still is necessary if you want the result to be written to the filepath. There will be no visual feedback during the render process.
# render settings
scene.render.image_settings.file_format = 'PNG'
scene.render.filepath = "F:/image.png"
bpy.ops.render.render(write_still = 1)
I'd post a result image, but it's just the default cube.