I am not very familiar with blender, more of a python programmer trying to use blender headless.

I want to import an STL to a scene and render an image from different angles. So I botched a code from here to do so, but I get a black picture.

This is my code:

import bpy
import os
from math import radians

context = bpy.context

#create a scene
scene = bpy.data.scenes.new("Scene")
camera_data = bpy.data.cameras.new("Camera")

camera = bpy.data.objects.new("Camera", camera_data)
camera.location = (-2.0, 3.0, 3.0)
camera.rotation_euler = ([radians(a) for a in (422.0, 0.0, 149)])

# do the same for lights etc

model_path = r"C:\Users\User\myfile.stl"
scene.camera = camera
path = os.path.join(models_path, model_path)
# make a new scene with cam and lights linked
context.screen.scene = scene
context.scene.name = model_path
cams = [c for c in context.scene.objects if c.type == 'CAMERA']
#import model
for c in cams:
    context.scene.camera = c                                    
    print("Render ", model_path, context.scene.name, c.name)
    context.scene.render.filepath = r"C:\Users\User\myoutput.png"

What am I doing wrong? Thanks!

  • $\begingroup$ Have you ever tried to turn on some lights? ;-) $\endgroup$ – Mechanic Jan 5 '19 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.