Asset Flinger Add-on - Simple Mesh Importer

EDIT (2015-05-03):

http://i.imgur.com/WskPrVw.jpg

Asset Flinger
Add-on for simple mesh importing via graphical menu.

Hi!

After a long journey that started of me trying to develop a Blender add-on by myself but eventually finding a couple of developers to contribute, Asset Flinger was made (even though it’s not fully functional for all operating systems yet).

It is now released as free to use for everyone. I hope you like it!

Read more and Download from the GitHub page

I would love to hear your comments on this!

Cheers!
Manu Järvinen

manujarvinen.com
fb.com/artofmanujarvinen
@manujarvinen


Original first post from 2013-05-28:

Hi

Having a folder full of single mesh objects like nuts, bolts and screws etc. as .blend or .obj files is a good start for an Asset Library.
However, appending objects into a scene starts to get tedious if you need to add them often to your scene - like I do.
So I really would like to have an addon for that.

I made a search for an asset library addon but there seems not to be many.
The best I found was this, but it makes each asset as a separate single addon and eventually menus get cluttered. Also distributing the whole asset library to others is immensely difficult.

I would love to have the Asset Library Addon handle a folder full of .obj files, in this manner:


Or even better would be with thumbnails:


Do any of you think this would be a possible addon to make?

I attached the assets as a .zip file to this post

Cheers,
mj

Attachments

Asset_Library.zip (242 KB)

Yeehaa, I already have what I need with the help from my friend and Jonathan’s menu tutorial.

Next step would be to make a nice thumbnail list.
And also an feature to sort the menu-entries into sub-menus in case the obj-folder has subfolders.

The current addon is attached to the post.

  • First open the python file and define your OBJ directory into it
  • Then just put it into \scripts\addons as usual and activate it in Blender
  • Lastly, assign a hotkey for it and you’re ready to go


And here’s the code:


bl_info = {
        "name": "OBJ Asset Library Menu",
        "category": "Import-Export"
        }        
 
import bpy

import os
# OBJ directory path. For example the following is c:\models\obj\
full_path_to_directory = os.path.join('C:\\', 'models', 'obj')

class PrimMaker( bpy.types.Operator ):
    filename = bpy.props.StringProperty()
    bl_idname = "bpt.obj_importer"
    bl_label = "Import OBJ file"
     
    def execute( self, context ):
        bpy.ops.import_scene.obj(filepath=self.filename)
        return {'FINISHED'}
   
# Creates a menu for global 3D View
class customMenu(bpy.types.Menu):
    bl_label = "OBJ Asset Library"
    bl_idname = "view3D.obj_asset_library_menu"
    # Set the menu operators and draw functions
    def draw(self, context):
        layout = self.layout
 
        # access this operator as a submenu
        # get list of all files in directory
        file_list = os.listdir(full_path_to_directory)
         
        # reduce the list to files ending in 'obj'
        # using 'list comprehensions'
        obj_list = [item for item in file_list if item[-3:] == 'obj']
         
        # loop through the strings in obj_list.
        for item in obj_list:
            filename = os.path.join(full_path_to_directory, item)
            layout.operator("bpt.obj_importer", text="" + item).filename = filename

def register():
    bpy.utils.register_class( PrimMaker )
    bpy.utils.register_class(customMenu)
 
def unregister():
    bpy.utils.unregister_class(customMenu)
    bpy.utils.register_class( PrimMaker )
 
if __name__ == "__main__":
    register()

Attachments

obj_import_menu_addon_v1.zip (873 Bytes)

  • sub-menus added
  • installation is a breeze, all the .obj files come with the addon
  • it’s easy to add your own .obj files and subfolders
  • it goes straight to the add mesh menu, no need for a keyboard shortcut

If someone happened to know how to get those thumbnail-images to be listed instead of the file names, that would be just golden!
I included the thumbnail-images to the released addon .zip file (attached to this post).

Cheers!



bl_info = {
        "name": "Asset Library",
        "version": (2, 0),
        "blender": (2, 67, 0),
        "location": "View3D > Add > Mesh > Asset Library",
        "description": "Asset Library of the .obj files in the addon's folder",
        "category": "Add Mesh"}        
 
import bpy
import os

folderDict = {}


# Fetching the path to Blender's addons directory
path_to_addons = os.path.sys.path[1]
if 'addons' not in path_to_addons:
    path_to_addons = os.path.sys.path[0]

# Full path to "\addons\add_mesh_asset_library\assets\" -directory
full_path_to_directory = os.path.join(path_to_addons, 'add_mesh_asset_library', 'assets')

class opOBJImporter( bpy.types.Operator ):
    filename = bpy.props.StringProperty()
    bl_idname = "bpt.obj_importer"
    bl_label = "Import OBJ file"
     
    def execute( self, context ):
        bpy.ops.import_scene.obj(filepath=self.filename)
        return {'FINISHED'}

class subMenuClass(bpy.types.Menu):
    bl_label = "Asset Library Submenu"
    bl_idname = "asset_library_submenu"
    
    # Set the menu operators and draw functions
    def draw(self, context):
        layout = self.layout
        folderName = self.bl_idname.split('.')[1]
        print (folderName)
        dir = os.path.join(full_path_to_directory, folderName)
        addOperatorsToLayout(dir, layout)    
                
def addOperatorsToLayout(dir, layout):
    file_list = os.listdir(dir)
    for name in file_list:
        if name[-3:] == 'obj':
            filename = os.path.join(dir, name)
            layout.operator("bpt.obj_importer", text="" + name, icon="MESH_ICOSPHERE").filename = filename

def createSubMenu(folderName):
    class InheritedClass(subMenuClass):
        bl_idname = "asset_library_submenu" + "." + folderName
        
    return InheritedClass
  
# Creates a menu for global 3D View
class customMenu(bpy.types.Menu):
    bl_label = "Asset Library"
    bl_idname = "view3D.asset_library"
    
    # Set the menu operators and draw functions
    def draw(self, context):
       
        layout = self.layout
 
        # access this operator as a submenu
        # get list of all files in directory
        file_list = os.listdir(full_path_to_directory)
         
        # reduce the list to files ending in 'obj'
        # using 'list comprehensions'
        obj_list = [item for item in file_list if item[-3:] == 'obj']
        
        file_list = os.listdir(full_path_to_directory)
        for name in file_list:
            if os.path.isdir(os.path.join(full_path_to_directory, name)):
                layout.menu(folderDict[name], text="" + name, icon="FILE_FOLDER")
                
        addOperatorsToLayout(full_path_to_directory, layout)

        
def menu_draw(self, context):
    layout = self.layout
    layout.separator()
    layout.menu(customMenu.bl_idname, icon='MOD_SCREW')


def register():
    bpy.utils.register_class( opOBJImporter )
    bpy.utils.register_class( customMenu )
    file_list = os.listdir(full_path_to_directory)
    for name in file_list:
        if os.path.isdir(os.path.join(full_path_to_directory, name)):
            newMenuClass = createSubMenu(name)
            bpy.utils.register_class(newMenuClass)
            folderDict[name] = newMenuClass.bl_idname
    bpy.types.INFO_MT_mesh_add.append(menu_draw)


def unregister():
    bpy.utils.unregister_class( customMenu )
    bpy.utils.unregister_class( opOBJImporter )
    bpy.types.INFO_MT_mesh_add.remove(menu_draw)

if __name__ == "__main__":
    register()


Attachments

BlenderAid_Asset_Library_Addon_v2.0.zip (568 KB)

hi maxon, very nice work, if your interested, drop into irc freenode #blenderpython for a chat. :slight_smile:

this is amazing! please make those thumbnails fast before i’ll find you and kill you because you didn’t make those in time! :stuck_out_tongue: :smiley:
WE NEED THIS! :smiley:

I like this. I like it’s simplicity.

life saving script! thanks!

Would be cool to be able to use .blend files along with obj’s. Would that be possible?

This addon is not working with blender 2.69 any chance to update it, it looks super useful.

at line 16 from init.py into the addons folder replace from:
path_to_addons = os.path.sys.path[1]
if ‘addons’ not in path_to_addons:
path_to_addons = os.path.sys.path[0]

to:

path_to_addons = os.path.sys.path[0]
if ‘addons’ not in path_to_addons:
path_to_addons = os.path.sys.path[1]


it is not working under 2.71 gives me error messages, can You update it? Plese, plese, your addon is amazing!

Thanks for the feedback! :slight_smile:

I hassled something and got it somehow to work in Blender 2.71.
Find the version 2.1 from attachment.

At first when I was in Windows-computer @predat’s advice didn’t work.
But on my home Mac laptop it was needed to get it work

Installing:

  • open the addons tab from user preferences
  • click: “Install from File…
  • select: BlenderAid_Asset_Library_Addon_v2.1.zip

Please, report back if it doesn’t work

However, I’m fully working on version 3.0, which has image thumbnails. Here’s a sneak peek.
I will probably publish it on the Blender Market.
So it will have better support from me perhaps.

Uhm… my skills won’t go that far :confused:
But if someone can advice how to do that it would be awesome :slight_smile:

Attachments

BlenderAid_Asset_Library_Addon_v2.1.zip (420 KB)

wow, the thumbnailed version will be awesome, probably will buy.
Thanks for the trying to fix it, unfortunately it’s still don’t working for me


I would buy that…

I got the same error, but if you move the unziped folder to the addons folder like this:


It works for me.

Asset Flinger released!
Check out the edited first post

great job guys, thanks a lot…! a pleasure to use, and also your models are cool
3d view overlay works nicely, but fails for me on quad view…
anyway, hope the asset management system in developement looks a bit like this

edit: you maybe should remove the smooth / subsurf code from thumbnailer
also a picture because this is too cool: https://db.tt/EdXnESj4

Thank you for the feedback!

Yeah, I put the quad view bug as well to the known bugs list.

Thanks, the code sure could be optimized a bit and clutter removed

Thanks for the picture! :smiley:
I want to put it here straight to the thread for display!

http://i.imgur.com/HcVwxZZ.jpg

But yeah, in the image there’s another of the known issues showing, which is that there is no possibility to scroll the list :confused: - It is, however, relatively easy to change the thumbnail sizes in the code for the menu and thumbnailer and then render new thumbnails - in order to get the list more compact

Manu this is FANTASTIC!!! Thanks so much for sharing (thank the anonymous contributors as well:) )

Thank you for sharing this add-on. It’s really great!
I decided to use this in my work.

This is my opinion.
After pressing SHIFT+CTRL+ALT+A key, short cut keys (T key and N key for shelf) need to be enabled,
because these shelves are overlapped on the Asset thumbnails.

Anyway, Thanks!