I am using Blender as Python Module on Mac and now attempting to create a scene programmatically and take a screenshot of what the camera sees but I am getting a "Segmentation Fault: 11" when running the following script (on calling bpy.ops.render.render).
import bpy
import mathutils
import bmesh
scene = bpy.context.scene
# Create the cube
mesh = bpy.data.meshes.new('cube')
ob = bpy.data.objects.new('cube', mesh)
scene.collection.objects.link(ob)
bm = bmesh.new()
bmesh.ops.create_cube(bm, size=1.0)
bm.to_mesh(mesh)
bm.free()
# Create a light
light_data = bpy.data.lights.new('light', type='POINT')
light = bpy.data.objects.new('light', light_data)
scene.collection.objects.link(light)
light.location = mathutils.Vector((3, -4.2, 5))
# Create the camera
cam_data = bpy.data.cameras.new('camera')
cam = bpy.data.objects.new('camera', cam_data)
scene.collection.objects.link(cam)
scene.camera = cam
cam.location = mathutils.Vector((6, -3, 5))
cam.rotation_euler = mathutils.Euler((0.9, 0.0, 1.1))
# Render settings
scene.render.image_settings.file_format = 'PNG'
filepath = "/tmp/image_blender.png"
# Segmentation fault caused by this line
bpy.ops.render.render(write_still = 1)
img = bpy.data.images['Render Result']
img.save_render(filepath, scene=scene)
I'd love to get some help and understand if there's an issue with the script or with the way I installed/configured Blender as a python module. Thanks in advance!
blender -b
from the command prompt. docs.blender.org/manual/en/latest/advanced/command_line/… $\endgroup$