Is there a way to open two blender files simultaneously through python?

I’m using blender as a python package. I’m looking for a way to extract position and bounding_box information about the meshes in a file, while I have opened another. The key part is that I need to read the second file, while do no change the current context. Is there a way to simply extract that data from a blend file or is there a way to run two bpy instances without having two python instances?

Thanks in advace!

You should Link the file in as a library, instead of trying to open it separately.

use subprocess.Popen to Pipe blender into a script. I do that for Blender-Organizer.

You can do

blender -b <secondfile.blend> -P <>

in the command line to open blender in the background. Then using print() you can extract all the data you need and write it into a PIPE… Which reads your main script.

First script will look something like this.

from subprocess import *
filename = "blenderfile.blend"
secondscriptname = ""
process = Popen(['stdbuf', '-o0',  "blender" ,"-b", filename,"-P", secondscriptname], stdout=PIPE, universal_newlines=True)
r = process.stdout.readline()[:-1]
while r:
    r # this is lines printed from the second script
    r = process.stdout.readline()[:-1]

Thanks, I will look into it. So the idea is to link the object, read their data and then unlink them?

I’m using blender as python module and I do not have blender especially because the script runs headless. So essentially I need to start second python instance. I just hoped I do not need to go there :slight_smile:

Yes, except there isn’t really a need to unlink it. I haven’t tried to do this through Python before but if you can’t figure it out I can try and help.