#NEWLINE# def _call_blender( filename , code ) : #NEWLINE# #INDENT# "Call blender, while running the given code. If the filename doesn't exist, save a new file in that location.\n    New files will be initially cleared by deleting all objects.\n    " #NEWLINE# with tempfile . NamedTemporaryFile ( ) as tf : #NEWLINE# #INDENT# print ( ( 'In new named temp file: %s' % tf . name ) ) #NEWLINE# startcode = _base_imports #NEWLINE# endcode = "\nbpy.ops.wm.save_mainfile(filepath='{fname}')" . format ( fname = filename ) #NEWLINE# cmd = 'blender -b {fname} -P {tfname}' . format ( fname = filename , tfname = tf . name ) #NEWLINE# if ( not os . path . exists ( filename ) ) : #NEWLINE# #INDENT# startcode += 'blendlib.clear_all()\n' #NEWLINE# cmd = 'blender -b -P {tfname}' . format ( tfname = tf . name ) #NEWLINE# #UNINDENT# tf . write ( ( ( startcode + code ) + endcode ) ) #NEWLINE# tf . flush ( ) #NEWLINE# sp . call ( shlex . split ( cmd ) )