Store data during a blender session

When using my scientific visualization addon I need to have access to a 3D data field for coloring meshes.


This addon needs to have a parameter field. It would be nice if we could store this for the course of the program; now we generate/read the data over and over again for every frame in which meshes need to be re-colored.

an operator property? or something more persistent? You can “abuse” operator classes to store python variables, just access them via self.class.varname (static member)

This looks like a cool trick!I don’t like putting my data as a static member of the operator class, but the same can be done using the current scene:

scene:bpy.context.scene.__class__.colorMesh = 

With this trick, the coloring of objects during a movie loop has become a lot simpler.Thanks!

I don’t have an answer to your question. But what a fantastic addon you made! I really think this is absolutely useful for scientific visualisation. This deserves more attention.:wink:

Thanks! If you have any questions on using it, drop me a line.Using the above mentioned answer solves my first problem.The second question I mention on my blog is posted in this blenderartist forum as well. As soon as I have a satisfactory answer to that question, I will try to get my addon in the standard list of addons.

you could try to store data in regular python classes (also static members), that might actually work as well…

What do you mean with “regular python classes”?The method of storing it as a static member of the scene class works perfectly and fits nicely with the application of using the data on every frame change.

well yeah, it’s great that it works, but i wonder if there is a cleaner solution without polluting stock bpy classes.

a regular py class would be:

class MyDataStorage:
    my_static_var = "foobar"

so still static members and therefore globally accessible, but a class which is not derived from a bpy type.

Indeed, I could not agree more!
This is the answer I was looking for (why didn’t I think of this myself?)
The simplest use of this, in the context of my addon, would be:


import bpy
from radthcolormesh.colormesh import ColorMesh

class CMStorage :
    colorMesh = ColorMesh()
    
def applyColor(scene) :
    CMStorage.colorMesh.colorMesh('Suzanne')

bpy.app.handlers.frame_change_pre.append(applyColor)

which does the job!
The ColorMesh class is defined in my addon which must be loaded for this to work.

Great, thanks!