2
$\begingroup$

Execution of this code will write in .blend file structure Aaa with data bb == True.

class Aaa(bpy.types.PropertyGroup):
    bb: bpy.props.BoolProperty(default=False)
bpy.utils.register_class(Aaa)

bpy.types.Scene.aa = bpy.props.PointerProperty(type=Aaa)
bpy.context.scene.aa.bb = True

del bpy.types.Scene.aa

bpy.types.Scene.aa = bpy.props.PointerProperty(type=Aaa)
print(bpy.context.scene.aa.bb)

How to delete this data from the .blend file if del bpy.types.Scene.aa removes only the api-defined by which they are read?

And how do I make sure that data with this structure is guaranteed to be missing in .blend file?

$\endgroup$
1
  • $\begingroup$ bpy.ops.wm.properties_remove(data_path = 'scene', property_name = 'aa') ? $\endgroup$ Commented Nov 15, 2023 at 7:33

2 Answers 2

3
+50
$\begingroup$

Pop a custom property

import bpy

class Aaa(bpy.types.PropertyGroup):
    bb: bpy.props.BoolProperty(default=False)
bpy.utils.register_class(Aaa)

bpy.types.Scene.aa = bpy.props.PointerProperty(type=Aaa)
bpy.context.scene.aa.bb = True

del bpy.types.Scene.aa

bpy.context.scene.pop("aa")

print(hasattr(bpy.context.scene, "aa"))
print("aa" in bpy.context.scene)
output:
False
False

You can make sure the property is removed from
Outliner

enter image description here

Please note that the UI will not update immediately after running the code, you will need to switch to a different tab and switch back manually.

$\endgroup$
2
$\begingroup$

del bpy.types.Scene.aa will remove the "API defined" flag on the property and it will prevent any new scene to mandatorily get this property assigned, but it won't remove it from scenes which already had it assigned. You can delete it with del scene["aa"]

Something like

for scene in bpy.data.scenes:
    if "aa" in scene:
        del scene["aa"]
$\endgroup$

You must log in to answer this question.

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