For a workflow tool I made a panel in which it displays each separate library that is linked in my file. For each library I want to add some buttons that does stuff to the library in question.
So in this example I have my panel which shows for example 2 libraries and for each one it creates a "reload" button.
Now my question is.. How do I make it so the reload button only reloads the library I want to reload? I would probably have to give the button an id or something so it knows for which library it was created...
my code so far:
import bpy
libs = bpy.data.libraries
class Reloadlib(bpy.types.Operator):
"""Reloads the current Library"""
bl_idname = "my.reload_lib"
bl_label = "Reload"
def execute(self, context):
libs[?????].reload()
self.report({'INFO'}, 'Reloading ' + libs[?????].name)
return {'FINISHED'}
class LibPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Scene Libraries"
bl_idname = "SCENE_PT_layout"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
layout.label(text="Libraries:")
for i in libs:
layout.label(text= i.name.replace(".blend",""))
row = layout.row()
sub = row.row()
sub.operator("my.reload_xref", icon = "FILE_REFRESH")
def register():
bpy.utils.register_class(Reloadlib)
bpy.utils.register_class(LibPanel)
def unregister():
bpy.utils.unregister_class(Reloadlib)
bpy.utils.unregister_class(LibPanel)
if __name__ == "__main__":
register()
Where the question marks are is where I should be able to make the difference between the first [0]
or second [1]
library in the libs[]
array.
In future I would also like to ad an 'open' and an 'unlink' button for each library so I can make changes to the other file. But this works by the same principle as the reload button.
reload_xref
meant to bereload_lib
? $\endgroup$