1

How to add/remove bpy.props Properties to/from existing PropertyGroup in Blender 2.91?

Let's say I've done the following:

import bpy

class MyProps(bpy.types.PropertyGroup): test1 : bpy.props.IntProperty()

bpy.utils.register_class(MyProps) bpy.types.Object.my_props = bpy.props.PointerProperty(type=MyProps)

How can I add "test2" IntProperty() to bpy.types.Object.my_props after that? And how can I remove it afterwards if I need to? I've tried to find something inside bpy.types.Object.my_props, bpy.types.Object.my_props[1]['type'], bpy.context.object.my_props - but there's nothing which would look like adding/removing methods.

Basically this is the same question as this: Remove from CollectionProperty but the described solution doesn't work for 2.91 anymore. I can't find .remove(), .clear(), .add() and any similar method which would allow to dynamically add/remove Properties to/from existing registered PropertyGroup.

Am I missing something?

Andrey Sokolov
  • 1,111
  • 10
  • 25
  • 2
    Hello, you need to use a CollectionProperty instead of a PointerProperty. The methods in the question you provided still work, but they need a Collection property. A PointerProperty only links to a single PropertyGroup, and a CollectionProperty to a dynamic collection of props. – Gorgious Feb 17 '21 at 20:53
  • Thank you! I see my mistake now. It helps! ) – Andrey Sokolov Feb 17 '21 at 21:43

0 Answers0