I wanted to declare a class instance and make it available from anywhere (like other scripts and the python console). Here’s what I hacked together:
import bpy
class stowAway:
"""Stow Away class"""
internalVal = 10
def selfInc(self):
self.internalVal += 10
def ack(self):
return 'stoAway class reporting'
def getVal(self):
return self.internalVal
scn = bpy.context.scene
x = stowAway()
def passer(scn):
global x
return x
# get the class from "anywhere" using:
# bpy.app.handlers.frame_change_pre[0](bpy.context.scene)
for n in range(len(bpy.app.handlers.frame_change_pre)):
if bpy.app.handlers.frame_change_pre[n].__name__ == "passer":
del bpy.app.handlers.frame_change_pre[n]
break
bpy.app.handlers.frame_change_pre.append(passer)
I append the function “passer” to one of the handlers, in this case “frame_change_pre”. When the function is called it returns the instance of the class, so when it’s called by “frame_change_pre” it doesn’t do anything. From anywhere else, I access it like this:
bpy.app.handlers.frame_change_pre[0](bpy.context.scene).ack()
Obviously this is a hack, but is there a better way to do this without registering an addon? It’s likely that I don’t understand Blender namespaces, so if there’a another way to do it please let me know…