1
$\begingroup$

I am having some trouble. Basically, when I load up this script, I see a panel drawn with a simple value that can be changed.

The value shows as expected in the UI, and the propertygroup I see exists as expected under bpy.data.scenes['Scene']['PerspectiveSettings'], but not the LineCount value. My expectation is that when the PropertyGroup is registered, it would register the properties with their default values (not sure if this is a correct expectation or not)

Is there anything I can do to initialize the LineCount property under bpy.data.scenes['Scene']['PerspectiveSettings'].['LineCount'] on startup?

    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()
$\endgroup$
2
  • $\begingroup$ This may help ? blender.stackexchange.com/a/227679/86891 $\endgroup$
    – Gorgious
    Aug 20, 2022 at 17:49
  • $\begingroup$ Unfortunately I don't think so, everything is drawn in the UI correctly, it just doesn't exist in blenders "insides" until the values are changed in the UI. $\endgroup$
    – NC_Sketchy
    Aug 21, 2022 at 15:20

1 Answer 1

1
$\begingroup$

Apparently this should be chalked up to my general lack of Python knowledge. After poking around in the Python Console I noticed that while

bpy.data.scenes['Scene']['PerspectiveSettings']['LineCount']

does not exist until the UI is modified. But,

bpy.data.scenes['Scene'].PerspectiveSettings.LineCount

DOES exist.

Why, no idea, but this appears to be it.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .