I have created a basic addon that loads text files and applies some game logic. In its script form it works fine, no problems, however when I try install it as an addon I get the pyrna_struct_meta_idprop_setattro() readonly error when trying to assign my scene variables.
I did some research and found a method that uses an initialize button which seems to work.
import bpy
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
# If Scene.my_prop wasn't created in register() or removed, draw a note
if not hasattr(context.scene, "my_prop"):
layout.label("Scene does not have a property 'my_prop'")
# If it has no longer the default property value, draw a label with icon
elif context.scene.my_prop != 'default value':
layout.label("my_prop = " + context.scene.my_prop, icon="FILE_TICK")
# It has the default property value, draw a label with no icon
else:
layout.label("my_prop = " + context.scene.my_prop)
layout.operator(InitMyPropOperator.bl_idname, text=InitMyPropOperator.bl_label)
class InitMyPropOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "scene.init_my_prop"
bl_label = "Init my_prop"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
if context.scene.my_prop != "initialized":
context.scene.my_prop = "initialized"
self.__class__.bl_label = "Change my_prop"
else:
context.scene.my_prop = "foobar"
self.__class__.bl_label = self.bl_label
return {'FINISHED'}
def register():
bpy.utils.register_module(__name__)
bpy.types.Scene.my_prop = bpy.props.StringProperty(default="default value")
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Scene.my_prop
if __name__ == "__main__":
register()
Worst-case scenario I will probably end up using this, however if possible I would like to avoid it.
Are there other ways of storing variables like this which can be referenced across multiple modules? (I have 1 Enum property for a drop down list, and 1 Integer property which is updated and changed).
The script only runs on Camera objects.
Thanks!