6
$\begingroup$

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

$\endgroup$
9
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ -"dataBrush = bpy.data.brushes "- give me ~ the same error message: AttributeError:'_restrictContext' object has no attribute 'brushes' $\endgroup$ – Issanou Kamardine IK Feb 8 '15 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 '15 at 12:13
  • $\begingroup$ ideasman42♦ I just need the current list of brushes to run the script, how can I make this happen ? $\endgroup$ – Issanou Kamardine IK Feb 9 '15 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 '15 at 14:53
  • 1
    $\begingroup$ @ideasman42 nice explanation of WHY it had been disabled in the end. Makes perfect sense to me now. $\endgroup$ – aliasguru Apr 2 '17 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.