I got my python script to render 2.D images somehow working while running in the text editor. Now I tried to copy some plugin infrastructure code around and get this error message:
File "/home/andreas/.config/blender/3.0/scripts/addons/blender-render-direction/__init__.py", line 7, in <module>
from . import blender_render_direction
File "/home/andreas/.config/blender/3.0/scripts/addons/blender-render-direction/blender_render_direction.py", line 563, in <module>
bpy.context.scene.my_list.clear()
AttributeError: '_RestrictContext' object has no attribute 'scene'
for a in bpy.data.actions:
item = bpy.context.scene.my_list.add()
item.name = a.name
Without looking too deep I assume this part at the bottom of the script should be registered and unregistered too. Assigning in register, and .clear() in unregister. Also I don’t see my_list registered anywhere. You need to register it as scene property, and delete it in unregister
def register():
from bpy.utils import register_class
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
Do this at the bottom of your script and replace list int he classes with every class you have. Unregistering them won’t be a problem anymore. Indentation isn’t shown here for some reason.
As for UI lists, they’re really mess to work with. What I is every time is open Blender add-on that has UI list, copy its code and just change everything until it fits my project.
I could add buttons to add new items or delete them. But I like to add new content. Before I modified the script to an addon it worked, but now I couldn’t get it running again. So how could I add() elements without the operator from the example.
If I have this in the register method I get an error:
# populate the action animations list with items
for a in bpy.data.actions:
item = bpy.context.scene.my_list.add()
item.name = a.name
File "/home/andreas/.config/blender/3.0/scripts/addons/blender-render-direction/blender_render_direction.py", line 567, in register
bpy.utils.register_class(cls)
File "/home/andreas/.config/blender/3.0/scripts/addons/blender-render-direction/blender_render_direction.py", line 346, in register
for a in bpy.data.actions:
AttributeError: '_RestrictData' object has no attribute 'actions'
But this would be only half of the solution as I need to “sync” this list somehow to the list of actions. So if actions are changed I need to be informed (or I poll for it?)
Do you’ve a good UIList example where I could see how this works? I didn’t find one with google.
Ok, I managed to get it somehow running with an List Update Button workaround. I pushed it to my github repo and this is how it looks like:
The 3rd button with the small clock just triggers a manual list update. Not perfect, but good enough for this simple addon.
Thanks for your help!
Just a short gif of an isometric monster render generated with the addon as example:
The idea is to render a lot of animations and angle directions in a loop.