I’m started to control blender (2.61) using a little webserver script and sending commands to it from a browser. It’s running fine for changing object locations.
But as soon as i call bpy.ops.render.render from the script, blender crashes.
Any idea how to solve this?
Thanks,
Stephan
import threading
import http.server
import socketserver
from urllib.parse import urlparse
import time
import bpy
PORT = 8000
IP_ADDRESS = "localhost"
#IP_ADDRESS = "192.168.254.1"
global running
running = 1
class RequestHandler(http.server.BaseHTTPRequestHandler):
def _writeheaders(self):
self.send_response(200)
self.send_header('Content-type', 'text/html; charset=UTF-8')
self.end_headers()
def do_HEAD(self):
self._writeheaders()
def do_GET(self):
global running
parsed_path = urlparse(self.path)
#ctx = bpy.context.active_object
#print(ctx)
#bpy.ops.screen.screenshot(filepath="c:\ emp\ est8.bmp")
try:
params = dict([p.split('=') for p in parsed_path[4].split('&')])
except:
params = {}
print(params)
try:
running = int(params["running"])
except:
running = 1
try:
print("Here i am")
#Here it crashes!
bpy.ops.render.render(write_still=True)
except:
print("no xrot")
self._writeheaders()
retstr = """<HTML>
<HEAD><TITLE>Dummy response</TITLE></HEAD>
<BODY>dummy response</BODY>
</HTML>"""
self.wfile.write(retstr.encode('latin'))
print("running = ",running)
httpd = socketserver.TCPServer((IP_ADDRESS, PORT), RequestHandler)
class HttpThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
print("HTTP Server THREAD: started")
print("serving at port", PORT)
httpd.serve_forever()
print ("HTTP Server THREAD: finished")
class ControlThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
print("Control THREAD: started")
runcontrol = 1
while runcontrol >0:
if running < 1:
print("try server shutdown")
httpd.shutdown()
httpd.socket.close()
print("shutdown finished")
runcontrol = 0
time.sleep(1)
print ("Control THREAD: finished")
print ("SCRIPT: started")
http_thread = HttpThread()
http_thread.start()
control_thread = ControlThread()
control_thread.start()
print ("SCRIPT: finished")