Using Blender python API in scripts


I have an application in python which need to get information from a .blend file. My application MUST be “standalone” (not run by blender) and with the ability to load and get information from multiples files.

Problems :

  1. the Blender python module is only available when you launch your python script with blender file.blend -b -P My apps does lot’s of stuff without blender (Gui toolkit, network, …) so it’s really strange to run the apps within blender.

  2. This way only allow me to work with one file (the one that i open in the blender command line) and it’s impossible to load others files (Blender.Load() documentation says "If a Blender file is loaded the script ends immediately.

to summarize, I want to :

  1. import Blender module in every python apps I write
  2. Load different blender files

The actual solution I use is really crap: I have my apps, launch the blender process and communicate by sockets between the two process, I’m looking for something simpler.

Thank you :wink:

As far as I know, Blender module is internal to BLENDER application, so it wont be possible to use it w/o started instance of BLENDER app… It is like this cause Blender module relies on and works with objects from a .blend file which are NOT accessible while the .blend file isnt opened. In this situation the best is what acctually you’ve achieved already - to extract information for Blneder object by means of direct app-to-app communication. It is something that I havent achieved so far!!! But it gives at least the following option for further development:

  1. As your application external to BLENDER communicates with Blender itself, then it is possible to control it by sending appropriate control keys (like clicking a button on the keyboard). Blender app will react on that and you can even start a script which is designed to work inside BLENDER.

  2. Using the technique above (see 1.), you may extract info into a .TXT file which is possible to de-code (read) by using an external Python or any other application and use the data as it may fit your needs… :rolleyes:

Thank for you answer.

So it seem that I’m stuck with the “socket” pattern. It work, but it’s a little bit like “using a H bomb to kill a fly”. By the way i only want to extract the mesh of my blender files. The most important problem for me, other than the unneeded complexity of the program is the network load that sharing a big mesh between blender and my script cost and the cost of creating a data structure for it…

Still hope for a better solution in the future, thank for your answer.

If you just want to extract mesh data, you can launch a subprocess with Blender by “Blender -b drawing.blend -P”. The inside Blender just writes to stdout and you read that from the subprocess. No need to use sockets here. Sockets are only necessary if you would like to interact.