[Bf-committers] Using bpy* types in a standalone script?

tmohr at s.netic.de tmohr at s.netic.de
Wed May 2 00:20:47 CEST 2018


Hello,

Can I import bpy etc. in an own script (that is not running inside blender) to
make use
of these types?

The background is that I would like to export some object data from within python
using pickle.dumps() and import it in an own script to further process it there.

Exporting works, but when importing (in a standalone script, not inside blender)
then the
used data types are unknown.

I would like to export / import data this way because a python export then contains
all data in he known format.

It would be great if somebody could confirm / disconfirm if the bpy internal
types can be used or not.


Here is how I export the data:
import bpy
import pickle
import zlib

c = bpy.context
d = bpy.data

cp = pickle.dumps([c, d])
cz = zlib.compress(cp)
fd = open("/home/tmohr/blender/dcopy/dump.pz", "wb")
fd.write(cz)
fd.close()
print("Done")


Here is how I try to import the data again:
import zlib
import pickle
import pprint
import sys

sys.path.append("/opt/blender-2.79a-rc-linux-glibc219-x86_64/2.79/scripts/modules")

import bpy


fd = open(sys.argv[1], "rb")
cz = fd.read()
cp = zlib.decompress(cz)
c = pickle.loads(cp)

pp = pprint.PrettyPrinter(indent=4)
pp.pprint(c)




Thanks for any hints,
Torsten



More information about the Bf-committers mailing list