I have written several functions in blender scripting mode. I need to pass their variables through Matlab thanks to the py command (Matlab - Python connection). The problem is that these functions work only in Blender (I have written a simple example below).
I was wondering if there is a way to call blender in each python function in order to execute them (Python - Blender connection).
I have already read about the possibility to call blender from the script thanks to the "subprocess" function, but I have not understood very well how to do it.
A simple function can be:
def monkey(x_coord, y_coord, z_coord):
import bpy
bpy.ops.mesh.primitive_monkey_add(size = 2, enter_editmode= False, align = 'WORLD', location = (x_coord, y_coord, z_coord))
How can I modify it in order to run blender everytime the function is called from matlab?
Maybe it can be understand better by looking to what happen in matlab.
I write my function:
but when I call it from the command window the result is an error:
I think this is due to the fact the the bpy module is only defined in Blender. I was wondering if there was a command to place before import bpy to make Blender run and so, avoid the error.


blender -b your_scene.blend -P your_pyfile.pyor compile blender as submodule: https://wiki.blender.org/wiki/Building_Blender/Other/BlenderAsPyModule – brockmann Aug 22 '20 at 01:03