0
$\begingroup$

I have an addon with some modules. I would like to execute some code when I install the addon or when Blender starts if the addon is installed. I make a few custom properties, disable a few panels execute some operators etc.

I have the code in one of my modules. I tried just to have the code in the script, I tried to make an operator where the code is in invoke() and I tried to put the code under register(). All of this works when I just run the script in the editor. But none of this worked when I install the zipped package (including an init.py) as an addon.

$\endgroup$
1
  • $\begingroup$ You need to register a function that has the '@persistent' decoration. $\endgroup$ Dec 19, 2021 at 0:57

1 Answer 1

1
$\begingroup$

if you want to do something at the time of installing put the code in register function. when you turn on your addon in preferences panel the register function would be called and when you turn that of the unregister function would be called.

$\endgroup$
2
  • 1
    $\begingroup$ Yeah I tried that. But I am calling other operators like: bpy.context.space_data.context = 'SCENE' and I get this confusing error: AttributeError: '_RestrictContext' object has no attribute 'space_data'. Is this because some other Blender stuff (operators) aren't registred yet, or something? $\endgroup$
    – DrDress
    Nov 25, 2020 at 14:08
  • $\begingroup$ Because bpy.context.space_data really has no attribute context but has attribute type which (I guess) is what you are looking for. this is readonly. this link may help: blender.stackexchange.com/questions/107438/… $\endgroup$ Nov 25, 2020 at 15:49

You must log in to answer this question.

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