I got this error message when I try to enable my addon.

dataBrush = bpy.context.blend_data.brushes

AttributeError:'_RestrictContext' object has no attribute 'blend_data'

Please some help

Error in enablling addon

I am working on an dynamic palette for sculpt brushes enter image description here


1 Answer 1


Short answer: don't access blendfile data when an add-on loads.

This is an intentional limitation with add-on loading which was added because it caused so many errors with inexperienced developers not properly understanding how data should be accessed, in practice it's almost never what you really want, and if for some obscure reason it is, you better not do it in an add-on (just run a script directly).

The kind of bug this caused was:

  • Add-on loads, sets the active scene. eg: scene = bpy.context.scene
  • User changes active scene or loads another blend file.
  • User tries to use the add-on, which starts using the previous scene.

Enabling an add-on should always give the same results no matter what Blend file you have open.

Instead, your tools should read from the context when they are activated by the user.

  • $\begingroup$ -"dataBrush = bpy.data.brushes "- give me ~ the same error message: AttributeError:'_restrictContext' object has no attribute 'brushes' $\endgroup$ Feb 8, 2015 at 12:10
  • $\begingroup$ Yep, this is working as its intended. Whatever you want to do with the brushes, add this into code thats access from an operator, panel, menu etc... The current open blend file shouldn't influence an add-ons startup which should never depend on the currently open file, otherwise loading another blend file may make the addon fail. $\endgroup$
    – ideasman42
    Feb 8, 2015 at 12:13
  • 1
    $\begingroup$ ideasman42♦ I just need the current list of brushes to run the script, how can I make this happen ? $\endgroup$ Feb 9, 2015 at 12:00
  • $\begingroup$ You can't do this in an addon (while the addon initializes), but interested to know what you are attempting. $\endgroup$
    – ideasman42
    Feb 9, 2015 at 14:53
  • 2
    $\begingroup$ @ideasman42 nice explanation of WHY it had been disabled in the end. Makes perfect sense to me now. $\endgroup$
    – aliasguru
    Apr 2, 2017 at 9:39

You must log in to answer this question.

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