Ah, it’s beginning to make sense.
I believe I got it working!
I have a file called misc_functions.py
where I stored the restore_prop function:
def restore_prop(scene):
val = getattr(restore_prop, "val", None)
# Only change when the value differs to prevent
# unnecessary rna updates whenever undo is called
if val is not None and scene.neltulzSmartObject.primary_location_method != val:
scene.neltulzSmartObject.primary_location_method = val
Then, in my __init__.py
file, I had to import it like this:
#misc_functions
from . import misc_functions
inside def register():
I added
bpy.app.handlers.undo_post.append(misc_functions.restore_prop)
inside def unregister():
I added:
bpy.app.handlers.undo_post.remove(misc_functions.restore_prop)
In my properties.py
file, above my property group class
, I added:
def prop_store(self, context):
misc_functions.restore_prop.val = self.primary_location_method
Inside my class NeltulzSmartObject_IgnitProperties(PropertyGroup):
, I added the update:
primary_location_method_list = [
("SMART", "Smart", "Automatically create object based on context", "FAKE_USER_ON", 0),
("WORLD_ORIGIN", "World Origin", "Create object at World Origin", "WORLD", 1),
("CURSOR", "3D Cursor", "Create object at 3D Cursor Location", "CURSOR", 2),
("VIEWPORT", "Viewport", "Create object at Viewport Location", "RESTRICT_VIEW_ON", 3),
("CUSTOM", "Custom", "Create object at a custom location", "TOOL_SETTINGS", 4),
]
primary_location_method : EnumProperty(
items=primary_location_method_list,
description="Which to use (Default: Smart)",
default="SMART",
update=prop_store,
)
Verified, working.
Amazing. I can’t believe this works!
Thank you so much for your help with this!