You're blocking ads, which pay for BlenderNation. Read about other ways to support us.

Script a Reference Image Manager

14

liss.dominik writes:

Extend the Blender UI and script your own reference image manager!
Happy scripting 😉

14 Comments

  1. Well, it's nice to see something like this in Blender and I really appreciate this kind of work - but why? Dont get me wrong, it's a nice tool, but programs like PureRef and Kuadro are way more advanced and production ready.

    • I really didn't wrote this script to create a new tool. I just wanted to learn how to use the thumbnail dropdown in blender … and I think that the reference manager is a nice example for using those dropdowns This is also the reason why I didn't research any other tools. I just wanted to show the blender community how to use the thumbnails dropdowns and what you could do with it

      Hope that answers your question

  2. Thank you for having shared this script which was very useful ! Besides, the video was very interesting.

    However, I have a suggestion : would it be possible to improve the script by adding an interface allowing us to select the pictures repertory ?

  3. Another suggestion, or a todo list for me when I'll be more confident with blender, can we create a kind of 'viewer node' to see realtime results for procedural nodes in the node editor ( node wrangle is helpfull but not as good as an icon or thumbnail for some nodes ) The idea is to have something like substance designer, but i don't know if its doable...

    • Thanks a lot for your suggestion!
      Unfortunately I don't use nodes in blender … in this case I would have to learn how it works first and then figure a way how to implement your idea. I am afraid that I won't have the time to do all this. But I'll put it on my list

  4. New Media Supply on

    I see that the link is broken on YouTube, and that it is not elsewhere to download. So I typed it over from the video and tried to port it over to 2.80. Don't run the script below because it has some nasty errors, but maybe someone is interested in fixing it further for other users.

    import os
    import bpy
    import bpy.utils.previews

    def get_image(filepath):
    name = os.path.basename(filepath)
    if name not in bpy.data.images:
    bpy.ops.image.open(filepath = filepath)
    return bpy.data.images(name)

    def open_image(self, context):
    image = get_image(self.reference_images_enum)
    for area in bpy.context.screen.areas :
    if area.type == 'IMAGE_EDITOR' :
    area.spaces.active.image = image

    def get_previews_collection(self, context):
    images = []
    custom_icons = preview_collections["main"]
    directory = "C:\Icons"
    i = 0

    if directory == custom_icons.my_previews_dir:
    return custom_icons.my_previews

    for file in os.listdir(directory):
    if file.endswitch(".png"):
    fullpath = os.path.join(directory, file)
    custom_icons.load(file, fullpath, 'IMAGE')
    images.append((fullpath, file, fullpath, custom_icons(file).icon_id, i))
    i+=1

    custom_icons.my_previews = images
    custom_icons.my_previews_dir = directory
    return custom_icons.my_previews

    class ReferenceManagerPanel(bpy.types.Panel):
    """ A custom Panel in the viewport toolbar """
    bl_label = "Reference Images"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"

    def draw(self, context):
    layout = self.layout

    row = layout.row
    row.template_icon_view(context.window_manager, "reference_images_enum")

    row = layout.row
    row.prop(context.window_manager, "reference_images_enum")

    preview_collections = {}

    def register():
    bpy.types.WindowManager.reference_images_enum = bpy.props.EnumProperty(
    items = get_previews_collection,
    update = open_image
    )

    preview_collection = bpy.utils.previews.new()
    preview_collection.my_previews_dir = ""
    preview_collection.my_previews = ()
    preview_collections['main'] = preview_collection

    bpy.utils.register_class(ReferenceManagerPanel)

    def unregister():
    del bpy.types.Scene.reference_images_enum

    for preview_collection in preview_collections.values():
    bpy.utils.previews.remove(preview_collection)
    preview_collections.clear()

    bpy.utils.unregister_class(ReferenceManagerPanel)

    if __name__ == "__main__":
    register()

    • Seyed Morteza Kamali on

      Hi friend I fixed the problem
      Cheers

      import os
      import bpy
      import bpy.utils.previews

      def get_image(filepath):
      name = os.path.basename(filepath)
      if name not in bpy.data.images:
      bpy.ops.image.open(filepath = filepath)
      return bpy.data.images(name)

      def open_image(self, context):
      image = get_image(self.reference_images_enum)
      for area in bpy.context.screen.areas :
      if area.type == 'IMAGE_EDITOR' :
      area.spaces.active.image = image

      def get_previews_collection(self, context):
      images = []
      custom_icons = preview_collections["main"]
      directory = "C:\Icons"
      i = 0

      if directory == custom_icons.my_previews_dir:
      return custom_icons.my_previews

      for file in os.listdir(directory):
      if file.endswitch(".png"):
      fullpath = os.path.join(directory, file)
      custom_icons.load(file, fullpath, 'IMAGE')
      images.append((fullpath, file, fullpath, custom_icons(file).icon_id, i))
      i+=1

      custom_icons.my_previews = images
      custom_icons.my_previews_dir = directory
      return custom_icons.my_previews

      class ReferenceManagerPanel(bpy.types.Panel):
      """ A custom Panel in the viewport toolbar """
      bl_label = "Reference Images"
      bl_space_type = "VIEW_3D"
      bl_region_type = "TOOLS"

      def draw(self, context):
      layout = self.layout

      row = layout.row
      row.template_icon_view(context.window_manager, "reference_images_enum")

      row = layout.row
      row.prop(context.window_manager, "reference_images_enum")

      preview_collections = {}

      def register():
      bpy.types.WindowManager.reference_images_enum = bpy.props.EnumProperty(
      items = get_previews_collection,
      update = open_image
      )

      preview_collection = bpy.utils.previews.new()
      preview_collection.my_previews_dir = ""
      preview_collection.my_previews = ()
      preview_collections['main'] = preview_collection

      bpy.utils.register_class(ReferenceManagerPanel)

      def unregister():
      del bpy.types.Scene.reference_images_enum

      for preview_collection in preview_collections.values():
      bpy.utils.previews.remove(preview_collection)
      preview_collections.clear()

      bpy.utils.unregister_class(ReferenceManagerPanel)

      if __name__ == "__main__":
      register()

Leave A Reply

To add a profile picture to your message, register your email address with Gravatar.com. To protect your email address, create an account on BlenderNation and log in when posting a message.