How can make the state of a boolean property relative to the 3d view area? I need to keep unique boolean properties attached to screen area (view 3d) which may have at the same time different states depending on the context view area, like propertie lock camera to view or use local camera can have different state in different 3d view areas.



For now I managed to declare a variable but which reacts globally, it changes state in all views.

import bpy
from bpy.props import StringProperty, BoolProperty
from bpy.types import PropertyGroup, Panel, Scene
from bpy.utils import register_class, unregister_class


class MyPropertyGroup(PropertyGroup):
    My_Bool : BoolProperty()


class PANEL_PT_panel(Panel):
    bl_label = "Boolean relative to 3d view area"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "View" 

    def draw(self, context):
        scene = bpy.context.scene
        layout = self.layout

        row = layout.row(align=True)

        col = row.column()

        col.prop(scene.mybool, 'My_Bool', text="My Bool")


classes = (MyPropertyGroup, PANEL_PT_panel)

def register():
    for i in classes:
        register_class(i)

    bpy.types.Scene.mybool = bpy.props.PointerProperty(type=MyPropertyGroup)


def unregister():
    for i in classes:
        unregister_class(i)

    del bpy.types.Scene.mybool


if __name__ == "__main__":
    register()


how can I "contextualize" his state ?

there is a specific way to register it ?
Make it a screen collection property

The best fit would be bpy.types.Screen Then the issue is a screen can have many areas, and we cannot tack a rna property onto a bpy.types.Area 

I have fudged around this by keeping a collection indexed the same as the area collection, and make a collection item property the boolean. Eg context.screen.my_collection[i].my_bool where i = context.screen.areas[:].index(context.area) Would need some way to keep consistent when areas are merged, created.



Here I've populated on register, adding an item for a potential 20 areas per screen. 

import bpy
from bpy.props import StringProperty, BoolProperty
from bpy.types import PropertyGroup, Panel, Scene
from bpy.utils import register_class, unregister_class


class MyPropertyGroup(PropertyGroup):
    mybool : BoolProperty()


class PANEL_PT_panel(Panel):
    bl_label = "Boolean relative to 3d view area"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "View" 

    def draw(self, context):
        screen = context.screen # notice no bpy needed
        layout = self.layout

        row = layout.row(align=True)

        col = row.column()
        i = screen.areas[:].index(context.area)
        ap = screen.my_area_props[i] 
        col.prop(ap, 'mybool', text="My Bool")


classes = (MyPropertyGroup, PANEL_PT_panel)

def register():
    for i in classes:
        register_class(i)

    bpy.types.Screen.my_area_props = bpy.props.CollectionProperty(type=MyPropertyGroup)


def unregister():
    for i in classes:
        unregister_class(i)

    del bpy.types.Screen.my_area_props


if __name__ == "__main__":
    register()
    # over populate it
    for screen in bpy.data.screens:     
        screen.my_area_props.clear()
        for i in range(20):
            screen.my_area_props.add()