1
$\begingroup$

I want to create a collection property with certain sculpt brushes. Can this be done? I tried:

WindowManager.coll = CollectionProperty(type=bpy.types.Brush)

But I'm getting errors:

TypeError: CollectionProperty(...) expected an RNA type derived from ID
Exception in module register(): '/home/antoni4040/Documents/blender-2.79-linux-glibc219-i686/2.79/scripts/addons/Advanced_Brushes/__init__.py'
Traceback (most recent call last):
  File "/home/antoni4040/Documents/blender-2.79-linux-glibc219-i686/2.79/scripts/modules/addon_utils.py", line 350, in enable
    mod.register()
  File "/home/antoni4040/Documents/blender-2.79-linux-glibc219-i686/2.79/scripts/addons/Advanced_Brushes/__init__.py", line 23, in register
    registerBrushSelectionPanel()
  File "/home/antoni4040/Documents/blender-2.79-linux-glibc219-i686/2.79/scripts/addons/Advanced_Brushes/Brush_Menu/Brush_Menu.py", line 120, in registerBrushSelectionPanel
    WindowManager.coll = CollectionProperty(type=bpy.types.Brush)
ValueError: bpy_struct "WindowManager" registration error: coll could not register

Any ideas? Thanks

$\endgroup$

1 Answer 1

2
$\begingroup$

Make a PropertyGroup with a brush type member.

Can use a pointer property to point to an ID type, in this case a brush. brush = bpy.props.PointerProperty(type=bpy.types.Brush)

import bpy

# Assign a collection
class SceneSettingItem(bpy.types.PropertyGroup):
    name = bpy.props.StringProperty(name="Test Prop", default="Unknown")
    brush = bpy.props.PointerProperty(type=bpy.types.Brush)

bpy.utils.register_class(SceneSettingItem)

bpy.types.Scene.brushes = \
    bpy.props.CollectionProperty(type=SceneSettingItem)

print("Adding All Brushes")

for brush in bpy.data.brushes:
    my_item = bpy.context.scene.brushes.add()
    my_item.name = brush.name
    my_item.brush = brush

Python console check after running script above.

>>> C.scene.brushes['Twist'].brush
bpy.data.brushes['Twist']
$\endgroup$
1
  • $\begingroup$ Thanks. But to be totally honest, I was also wondering if I could add such a collection property to a template_ID_preview and get a preview with some custom brushes. Could you please tell me (if you know) if I'm on the right track or if I'm going the wrong way? $\endgroup$
    – Antoni4040
    Commented Dec 30, 2017 at 15:07

You must log in to answer this question.

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