# Reload pressing F8 will not restore property to default?

Is it possible to reload by pressing F8 and restore property to default value? I don't seem to get this working? If there's a way to do so, would it work with EnumProperty?

bpy.types.Scene.my_string_prop = bpy.props.StringProperty \
(
name = "Text Field",
description = "My description",
default = "some default text here"
)


In the panel def draw:

   def draw(self, context):
layout = self.layout

#Set TextField
col = layout.column(align = True)
col.prop(context.scene, "my_string_prop")

• Properties as above, eg scene.prop are "stored" as scene["prop"] once set to something other than default. Remove with scene.property_unset("prop") or del scene["prop"]. – batFINGER May 20 '18 at 5:14
• I put these in the unregister(): scene.property_unset("prop") del scene["prop"] still didn't work on F8, did i missed something? – adrian li May 20 '18 at 11:50
• When an addon is registered (ie in the register method), it has "restricted context" during which most data cannot be edited. Also your property is called "my_string_prop" so you would use (not in register method) scene.property_unset("my_string_prop") ... and it would have to be set up to be in F8... added an answer. – batFINGER May 20 '18 at 13:17

Make an operator to add functionality before calling another

The text editor > templates > python > Operator Simple template edited (minimally) to reset a user defined "xxxx" property of the scene to its default value. Can either use scene.property_unset("xxx") or simply remove its storage del(scene["xxx"]).

After which the reload script is called. (default op of F8) Edit the shortcut in user preferences to point to new operator.

the screen F8 shortcut after changing "script.reload" to "object.simple_operator"

import bpy

class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"

@classmethod
def poll(cls, context):
return True

def execute(self, context):
scene = context.scene
scene.property_unset("xxx")
#del(scene["xxx"]) # same
# what F8 calls
return {'FINISHED'}

def register():
bpy.types.Scene.xxx = bpy.props.IntProperty()
bpy.utils.register_class(SimpleOperator)

def unregister():
del(bpy.types.Scene.xxx)
bpy.utils.unregister_class(SimpleOperator)

if __name__ == "__main__":
register()
# test code
scene = bpy.context.scene
scene.xxx = 10
print("before", scene.xxx)
bpy.ops.object.simple_operator()
print("after", scene.xxx)

• I have employed your method and it seemed to make sense, however it doesnt seem to restore default bpy.props.StringProperty. I am editing the addon innit.py file as is in the text editor window inside blender and press "Run Script" to test things, could this be the problem why F8 wont work? If so, what should be the proper workflow to edit and test code on the fly(i have multiple python files)? – adrian li May 22 '18 at 7:30
• I put del bpy.types.Scene.my_string_prop in unregister() and F8 still doesnt revert it to default value? – adrian li May 22 '18 at 7:36