Persistent Data

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Posts: 0
Joined: Fri Nov 01, 2013 2:01 am

Persistent Data

Post by stonysmith »

First post here, might as well jump into the deep end:

I am trying to write a module in python that interfaces to a remote (secure) website.
I need to store some session information, and I don't think that it's correct to attach the data to any particular mesh object, nor the scene, nor the .blend file itself.

I need for this data to be in a place I can retrieve it as long as Blender is running.. it's the session identifier. I would expect the user to have to re-authenticate each time Blender is started. (don't want to store passwords, etc)

As I see it, there are two options:
1) write the data into some filesystem file
2) attach the data to some global Blender memory object that is "above" the currently opened .blend file.

so, questions:
1) If a filesystem file is used, is there a recommended place for user-temporary files? is there a property somewhere that points to a folder where I can write a temporary file?
2) Is there such a global object such that my session information can be retained as long as Blender is open?

BartV assured me that you friendly folks would have an answer :)

Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

You could use the window manager for a custom property:

Code: Select all

bpy.types.WindowManager.session = bpy.props.StringProperty(options={'HIDDEN', 'SKIP_SAVE'})

bpy.context.window_manager.session = "abc123"
SKIP_SAVE might not even be needed, but you better test that.

If you access the session in your addon's code only, you could use a class:

Code: Select all

class Storage:
    session = None

Storage.session = "abc123" # use as static member

If you need a cross-addons global var, some people use:

Code: Select all

bpy._session = "abc123"
since bpy is always available.
I'm sitting, waiting, wishing, building Blender in superstition...

Post Reply