1
$\begingroup$

I'm trying to get my addon and its categories and dropdown menus to show up in blender 2.8 like this: Simple Asset Manager , but can't seem to get anything to show up, I updated some of the code which I haven't posted here to 2.8, and only the tab on the toolshelf shows, not the dropdown or the preview.

# Update

def update_category(self, context):
    enum_previews_from_directory_items(self, context)


# Drop Down Menu
class Categories(bpy.types.PropertyGroup):
    mode_options = [
        ("Basic_Elements", "Elements", '', 0),


        ]

    options = bpy.props.EnumProperty(
        items=mode_options,
        description="Select a Category",
        default="Basic_Elements",
        update=update_category
    )


# Generate Previews
def enum_previews_from_directory_items(self, context):

    category = context.scene.transitions_elements.options

    # Icons Directory
    directory = os.path.join(os.path.dirname(__file__), "Icons" + os.sep + category)

    # EnumProperty Callback
    enum_items = []

    if context is None:
        return enum_items

    wm = context.window_manager

    # Get the Preview Collection (defined in register func)
    pcoll = preview_collections["main"]

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

    print("Scanning directory: %s" % directory)

    if directory and os.path.exists(directory):
        # Scan the Directory for PNG Files
        image_paths = []
        for fn in os.listdir(directory):
            if fn.lower().endswith(""):
                image_paths.append(fn)

        # For each image in the directory, load the thumb unless it has already been loaded
        for i, name in enumerate(image_paths):
            # Generate a Thumbnail Preview for a File.
            filepath = os.path.join(directory, name)

            if filepath in pcoll:
                enum_items.append((name, name, "", pcoll[filepath].icon_id, i))
            else:
                thumb = pcoll.load(filepath, filepath, 'IMAGE')
                enum_items.append((name, name, "", thumb.icon_id, i))

    pcoll.my_previews = enum_items
    pcoll.my_previews_dir = directory
    return pcoll.my_previews


#



#####################################################################

# Register
def register():

    global icons


    bpy.types.WindowManager.some_string = bpy.props.StringProperty(name="Enter Text")

    bpy.utils.register_module(__name__)

    WindowManager.my_previews_dir = StringProperty(
            name = "Folder Path",
            subtype = 'DIR_PATH',
            default = "")

    WindowManager.my_previews = EnumProperty(
            items = enum_previews_from_directory_items)

    pcoll = bpy.utils.previews.new()
    pcoll.my_previews_dir = ""
    pcoll.my_previews = ()

    preview_collections["main"] = pcoll
    bpy.types.Scene.transitions_elements = bpy.props.PointerProperty(type=Categories)


# Unregister
def unregister():
    bpy.utils.previews.remove(icons)
    del bpy.types.WindowManager.some_string
    del WindowManager.my_previews

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

    bpy.utils.unregister_module(__name__)

    del bpy.types.Scene.transitions_elements


if __name__ == '__main__':
    register()
$\endgroup$
  • $\begingroup$ Hello and welcome to BSE! Could you edit your question to include the relevant portions of the page you linked to? Thank you, and I hope we get get this answered for you. $\endgroup$ – TARDIS Maker Jan 9 at 6:45
  • $\begingroup$ Thank you! I've edited my question based on your suggestion. $\endgroup$ – Joshua197 Jan 9 at 15:44
  • $\begingroup$ Hi. In future if you need to amend your question you can use the edit link below it, instead of asking it again. $\endgroup$ – Ray Mairlot Jan 9 at 16:10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.