2015-05-23 21:59:40 +00:00
|
|
|
import bpy, sys, os
|
|
|
|
|
|
|
|
# Extract pipe file descriptors from arguments
|
2015-05-24 04:51:16 +00:00
|
|
|
print(sys.argv)
|
|
|
|
if '--' not in sys.argv:
|
|
|
|
bpy.ops.wm.quit_blender()
|
2015-05-23 21:59:40 +00:00
|
|
|
args = sys.argv[sys.argv.index('--')+1:]
|
|
|
|
readfd = int(args[0])
|
|
|
|
writefd = int(args[1])
|
|
|
|
|
|
|
|
def readpipeline():
|
|
|
|
retval = bytearray()
|
|
|
|
while True:
|
|
|
|
ch = os.read(readfd, 1)
|
|
|
|
if ch == b'\n' or ch == b'':
|
|
|
|
return retval
|
|
|
|
retval += ch
|
|
|
|
|
|
|
|
def writepipeline(linebytes):
|
2015-05-24 22:19:28 +00:00
|
|
|
os.write(writefd, linebytes + b'\n')
|
|
|
|
|
|
|
|
def writepipebuf(linebytes):
|
|
|
|
writepipeline(b'BUF')
|
|
|
|
os.write(writefd, struct.pack('I', len(linebytes)) + linebytes)
|
2015-05-23 21:59:40 +00:00
|
|
|
|
|
|
|
def quitblender():
|
|
|
|
writepipeline(b'QUITTING')
|
|
|
|
bpy.ops.wm.quit_blender()
|
|
|
|
|
2015-05-24 04:51:16 +00:00
|
|
|
# Check that HECL addon is installed/enabled
|
|
|
|
if 'hecl' not in bpy.context.user_preferences.addons:
|
|
|
|
if 'FINISHED' not in bpy.ops.wm.addon_enable(module='hecl'):
|
|
|
|
writepipeline(b'NOADDON')
|
|
|
|
bpy.ops.wm.quit_blender()
|
|
|
|
|
2015-05-24 22:19:28 +00:00
|
|
|
# Make addon available to commands
|
|
|
|
import hecl
|
|
|
|
|
2015-05-23 21:59:40 +00:00
|
|
|
# Intro handshake
|
|
|
|
writepipeline(b'READY')
|
|
|
|
ackbytes = readpipeline()
|
|
|
|
if ackbytes != b'ACK':
|
|
|
|
quitblender()
|
|
|
|
|
|
|
|
# Command loop
|
|
|
|
while True:
|
|
|
|
cmdline = readpipeline().split(b' ')
|
|
|
|
|
2015-05-24 22:19:28 +00:00
|
|
|
if cmdline[0] == b'QUIT':
|
2015-05-23 21:59:40 +00:00
|
|
|
quitblender()
|
|
|
|
|
|
|
|
elif cmdline[0] == b'OPEN':
|
2015-05-24 22:19:28 +00:00
|
|
|
if 'FINISHED' in bpy.ops.wm.open_mainfile(filepath=cmdline[1].decode()):
|
|
|
|
writepipeline(b'FINISHED')
|
|
|
|
else:
|
|
|
|
writepipeline(b'CANCELLED')
|
2015-05-24 04:51:16 +00:00
|
|
|
|
|
|
|
else:
|
2015-05-24 22:19:28 +00:00
|
|
|
hecl.command(cmdline, writepipeline, writepipebuf)
|
2015-05-23 21:59:40 +00:00
|
|
|
|