Hi All,
Problem: Custom properties I created do not seem to have their default values set or initialized until the value is manually changed.
I have a UI panel created with a property value in there. Its default looks correct from the UI perspective, but when I look for the property through the python console, it does not exist. IE: I tab through this:
bpy.data.scenes[‘Scene’][‘PerspectiveSettings’]
After I change the value in the panel, I now see things as expected, IE, this:
bpy.data.scenes[‘Scene’][‘PerspectiveSettings’][‘LineCount’]
How can I have the custom properties set correctly on startup?
Below is a watered down version of my code to the basics that are causing the problem. In reality I have a few more options, and buttons that are pressed that are dependent on the custom properties being in place.
import bpy
from bpy.props import PointerProperty, EnumProperty
class PERSPECTIVETOOLSPANEL_PT_main(bpy.types.Panel):
bl_idname = "PERSPECTIVEGRID_PT_main.panel"
bl_label = "Dummy Panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "DummyTest"
def draw(self, context):
scene = context.scene
layout = self.layout
PerspectiveSettings = context.scene.PerspectiveSettings
row1 = layout.row()
row1.prop(PerspectiveSettings, "LineCount", text="Line Count")
class PerspectiveSettings(bpy.types.PropertyGroup):
LineCount : bpy.props.IntProperty(
name = "LineCount",
description = "",
default = 20,
min = 1,
max = 100
)
def register():
bpy.utils.register_class(PerspectiveSettings)
bpy.types.Scene.PerspectiveSettings = bpy.props.PointerProperty(type=PerspectiveSettings)
bpy.utils.register_class(PERSPECTIVETOOLSPANEL_PT_main)
def unregister():
bpy.utils.unregister_class(PerspectiveSettings)
del bpy.types.Scene.PerspectiveSettings
bpy.utils.unregister_class(PERSPECTIVETOOLSPANEL_PT_main)
if __name__ == '__main__':
register()
I tried searching but couldn’t quite figure out what I am actually looking for/anything that made sense to me (Python newb). Any help would be much appreciated!