Skip to content
Snippets Groups Projects
io_import_BrushSet.py 5.25 KiB
Newer Older
  • Learn to ignore specific revisions
  • kromar's avatar
    kromar committed
    # This program is free software; you can redistribute it and/or
    # modify it under the terms of the GNU General Public License
    # as published by the Free Software Foundation; either version 2
    # of the License, or (at your option) any later version.
    
    kromar's avatar
    kromar committed
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    
    kromar's avatar
    kromar committed
    # You should have received a copy of the GNU General Public License
    # along with this program; if not, write to the Free Software Foundation,
    # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    
    kromar's avatar
    kromar committed
    # <pep8-80 compliant>
    
    kromar's avatar
    kromar committed
    # todo
    
    - add file selection for single and multiple files
    
    - option to enable/disable fake users
    '''
    
    #---------------------------------------------#
    
    kromar's avatar
    kromar committed
    # addon description
    
    Dan Grauer's avatar
    Dan Grauer committed
        "name": "import BrushSet",
    
    kromar's avatar
    kromar committed
        "version": (1, 2, 1),
    
        "blender": (2, 74, 0),
    
        "category": "Import-Export",
    
    Dan Grauer's avatar
    Dan Grauer committed
        "location": "File > Import > BrushSet",
        "description": "imports all image files from a folder",
    
    kromar's avatar
    kromar committed
        "warning": '',    # used for warning icon and text in addons panel
    
        "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/BrushSet",
    
        "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
    
    kromar's avatar
    kromar committed
    # extension filter (alternative use mimetypes)
    # TODO: rewrite so it tries to load image and if it fails we know its not a format blender can load
    
    ext_list = ['.bmp',
                '.png',
                '.jpg',
                '.jp2',
                '.rgb',
                '.dds',
                '.hdr',
                '.exr',
                '.dpx',
                '.cin',
                '.tga',
                '.tif'];
    
    #---------------------------------------------#
    
    fakeUser = False
    
    Dan Grauer's avatar
    Dan Grauer committed
        for file in os.listdir(filepath):
            path = (filepath + file)
    
    kromar's avatar
    kromar committed
            # get folder name
    
    Dan Grauer's avatar
    Dan Grauer committed
            (f1, f2) = os.path.split(filepath)
            (f3, foldername) = os.path.split(f1)
    
    kromar's avatar
    kromar committed
            # filter files by extensions (filter images)
    
            for i in ext_list:
                if file.endswith(i):
                    print("file: ", file)
    
    kromar's avatar
    kromar committed
                    # create new texture
    
                    texture = bpy.data.textures.new(file, 'IMAGE')
                    texture.use_fake_user = fakeUser
                    print("texture: ", texture)
    
    
    kromar's avatar
    kromar committed
                    # now we need to load the image into data
    
                    image = bpy.data.images.load(path)
                    image.use_fake_user = fakeUser
    
    kromar's avatar
    kromar committed
                    # image.source = 'FILE' #default is FILE so can remove this
                    # image.filepath = path
    
                    print("image: ", image, " ", path)
                    print("texturename: ", texture.name)
    
    
    kromar's avatar
    kromar committed
                    # and assign the image to the texture
    
    
    class BrushSetImporter(bpy.types.Operator):
    
    Dan Grauer's avatar
    Dan Grauer committed
        bl_idname = "import_image.brushset"
        bl_label = "Import BrushSet"
    
    
        filename = StringProperty(name = "File Name",
                                  description = "filepath",
                                  default = "",
                                  maxlen = 1024,
                                  options = {'ANIMATABLE'},
    
    kromar's avatar
    kromar committed
                                  subtype = 'NONE')
    
    
        filepath = StringProperty(name = "File Name",
                                  description = "filepath",
                                  default = "",
                                  maxlen = 1024,
                                  options = {'ANIMATABLE'},
    
    kromar's avatar
    kromar committed
                                  subtype = 'NONE')
    
    Dan Grauer's avatar
    Dan Grauer committed
        def execute(self, context):
            LoadBrushSet(self.properties.filepath, self.properties.filename)
            return {'FINISHED'}
    
        def invoke(self, context, event):
            wm = context.window_manager
            wm.fileselect_add(self)
            return {'RUNNING_MODAL'}
    
    
    kromar's avatar
    kromar committed
        # clear the default name for import
    
        import_name = ""
    
        self.layout.operator(BrushSetImporter.bl_idname, text = "Brush Set").filename = import_name
    
    kromar's avatar
    kromar committed
    # GUI
    
    #---------------------------------------------#
    
    '''
    class Brush_set_UI(bpy.types.Panel):
    
        bl_space_type ='USER_PREFERENCES'
        bl_label = 'Brush_Path'
        bl_region_type = 'WINDOW'
        bl_options = {'HIDE_HEADER'}
    
            layout = self.layout
            column = layout.column(align=True)
            column.label(text='Brush Directory:')
    
    Dan Grauer's avatar
    Dan Grauer committed
        bpy.utils.register_module(__name__)
    
        bpy.types.TOPBAR_MT_file_import.append(menu_func)
    
    Dan Grauer's avatar
    Dan Grauer committed
        bpy.utils.unregister_module(__name__)
    
        bpy.types.TOPBAR_MT_file_import.remove(menu_func)
    
    Dan Grauer's avatar
    Dan Grauer committed
        register()