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.

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.

• 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? – DrDress Nov 25 '20 at 14:08
• 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/… – MohammadHossein Jamshidi Nov 25 '20 at 15:49