I have this script that relies on a lot of custom scene properties. Initially I was able to default all of the floats in the function that registers the properties but when I turned it into an add-on the function started throwing an exception on registration (restricted context, preventing access to the scene during registration).
I removed those lines and it would register but I’d have problems with the enum properties. For example, with the following in the draw function:
if context.scene['data_path'] == 1 and (context.active_object.rotation_mode == 'QUATERNION' or context.active_object.rotation_mode == 'AXIS_ANGLE'):
row.prop(scene,'vector4')
else:
row.prop(scene,'vector3')
The data_path property didn’t have an integer value, even though I set a default during declaration, so it would throw an error until I selected an item from the data_path menu (location, rotation, or scale). But when I changed it from context.scene[‘data_path’] == 1 to context.scene.data_path == ‘Rotation’ it started working using the defaults set in the bpy.props.EnumProperty function.
Making those changes to the enum properties fixed all of those problems, the numeric values with a known default are set correctly, the boolean properties default to false like they’re supposed to, but I have trouble initializing variables that rely on a formula, specifically when the formula contains scene data like this:
scene = context.scene
scene.quarter = (60/scene.tempo) * (scene.render.fps/scene.render.fps_base)
scene.whole = scene.quarter * 4
...
scene.selected_note = scene.quarter
I have an update operator that you use to update the note values when you change the scene’s frame rate since I can’t seem to work that into a callback but is there any way to initialize it out of the box? Right now it’s set up so that the user has to manually refresh the values either with the operator or changing the time signature.
I’ve tried initializing the properties in the register function (throws an error when enabling the add-on), a boolean test in the draw function that calls an initialize function on the first run (throws an error since you can’t write to a property during a draw), and I also made an initialize operator where on registration you’ll just see an initialize button then when you press it the interface will appear with all of the values set to defaults, but I accomplish that by turning the panel’s draw function into one large if…else statement and I’m not sure what kind of impact that will have on performance.