I have developed a little addon that provides icon button in the node editor. We have 80 node items. And so i have 80 external icons to load. I use custom_icons.load for that.
The problem is, every icon loads one by one when activating the tab. You see them popping up one after another. The user has to wait until all the icons are loaded. And that's for our 80 icons around 10 seconds in Blender 2.78a. Not good.
Is there a way to load the external icons at Blender startup? If not, is there a way to load at least all icons at once?
The script is already a init.py, Examplecode looks like this. The icons are of course missing. Please add a folder called icons besides the script, and put two png images into the folder with the correct name:
import bpy
import os
import bpy.utils.previews
class NodesIconPanel(bpy.types.Panel):
"""Creates a Panel"""
bl_label = "All Nodes"
bl_idname = "nodes.common_buttons"
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'TOOLS'
bl_category = "All Nodes"
@staticmethod
def draw(self, context):
layout = self.layout
default_context = bpy.app.translations.contexts.default
##### --------------------------------- Layout ------------------------------------------- ####
layout.label(text="Layout:")
row = layout.row()
row.alignment = 'LEFT'
props = row.operator("node.add_node", text="", text_ctxt=default_context, icon_value = custom_icons["icon32_frame"].icon_id)
props.use_transform = True
props.type = "NodeFrame"
props = row.operator("node.add_node", text="", text_ctxt=default_context, icon_value = custom_icons["icon32_reroute"].icon_id)
props.use_transform = True
props.type = "NodeReroute"
# global variable to store icons in
custom_icons = None
def register():
bpy.utils.register_class(NodesIconPanel)
# Our external Icons
global custom_icons
custom_icons = bpy.utils.previews.new()
# Use this for addons
#icons_dir = os.path.join(os.path.dirname(__file__), "icons")
# Use this for testing the script in the scripting layout
script_path = bpy.context.space_data.text.filepath
icons_dir = os.path.join(os.path.dirname(script_path), "icons")
custom_icons.load("frame", os.path.join(icons_dir, "frame.png"), 'IMAGE')
custom_icons.load("reroute", os.path.join(icons_dir, "reroute.png"), 'IMAGE')
def unregister():
global custom_icons
bpy.utils.previews.remove(custom_icons)
bpy.utils.unregister_class(NodesIconPanel)
# This allows you to run the script directly from blenders text editor
# to test the addon without having to install it.
if __name__ == "__main__":
register()