Given this simple example, if you call foo.bar
directly (e.g. via F3 search menu) the float property X is remembered between subsequent calls. However, when invoked via a hotkey (e.g. activate foo tool and then press Shift+R) the property X resets to the default value (0).
It seems similar to this previous question though apparently it's a fixed bug so not sure if this is something different.
As a bonus, I also draw a non operator property, and wonder why you cannot change this value?
import bpy
class Fooprop(bpy.types.PropertyGroup):
x: bpy.props.FloatProperty(name="X", default=0.5)
class Foobar(bpy.types.Operator):
bl_idname = "foo.bar"
bl_label = "Foobar"
bl_options = {"REGISTER", "UNDO"}
x: bpy.props.FloatProperty(name="X")
def execute(self, context):
return {"FINISHED"}
def draw(self, context):
row = self.layout.row()
row.prop(self, "x")
row.prop(context.scene.Fooprop, "x")
def invoke(self, context, event):
return self.execute(context)
class FooTool(bpy.types.WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_label = "FooTool"
bl_context_mode = "OBJECT"
bl_idname = "foo.bar_tool"
bl_widget = None
bl_keymap = (("foo.bar", {"type": "R", "value": "PRESS", "shift": True}, {"properties": []}),)
bpy.utils.register_class(Foobar)
bpy.utils.register_class(Fooprop)
bpy.types.Scene.Fooprop = bpy.props.PointerProperty(type=Fooprop)
bpy.utils.register_tool(FooTool, after={"builtin.scale_cage"}, separator=True, group=True)
```