Newer
Older
Dan Grauer
committed
# ##### BEGIN GPL LICENSE BLOCK #####
Dan Grauer
committed
#
Dan Grauer
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.
Dan Grauer
committed
#
Dan Grauer
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.
Dan Grauer
committed
#
Dan Grauer
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.
Dan Grauer
committed
#
Dan Grauer
committed
# ##### END GPL LICENSE BLOCK #####
Dan Grauer
committed
Dan Grauer
committed
# <pep8-80 compliant>
Dan Grauer
committed
#---------------------------------------------#
# todo
#---------------------------------------------#
'''
Dan Grauer
committed
- add file selection for single and multiple files
Dan Grauer
committed
- option to enable/disable fake users
'''
#---------------------------------------------#
# changelog
#---------------------------------------------#
CoDEmanX
committed
'''
Dan Grauer
committed
"version": (1,2,0)
- added missing texture types
- new way to filter file types
- option for fake user flag
CoDEmanX
committed
Dan Grauer
committed
"version": (1,1,5)
- changed addon category to Import-Export
CoDEmanX
committed
"version": (1,1,4),
filename will be used as texture name (still limited by stringlength)
Dan Grauer
committed
Dan Grauer
committed
fixed operator and registration
added tracker and wiki url\
CoDEmanX
committed
Dan Grauer
committed
version": (1,1,2)
replaced image.new() with image.load()
changed addon category
CoDEmanX
committed
removed some unused/old code
Dan Grauer
committed
version":1.11:
added type arg to texture.new() [L48]
cleared default filename
'''
Dan Grauer
committed
#---------------------------------------------#
Dan Grauer
committed
import bpy
import os
from bpy.props import *
#addon description
bl_info = {
Dan Grauer
committed
"author": "Daniel Grauer (kromar)",
"version": (1, 2, 0),
CoDEmanX
committed
"blender": (2, 64, 0),
"location": "File > Import > BrushSet",
"description": "imports all image files from a folder",
"warning": '', # used for warning icon and text in addons panel
Dan Grauer
committed
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/BrushSet",
CoDEmanX
committed
"tracker_url": "https://developer.blender.org/T25702",
Dan Grauer
committed
#---------------------------------------------#
# extension filter (alternative use mimetypes)
ext_list = ['.bmp',
'.png',
'.jpg',
'.jp2',
'.rgb',
'.dds',
'.hdr',
'.exr',
'.dpx',
'.cin',
'.tga',
'.tif'];
#---------------------------------------------#
fakeUser = False
Dan Grauer
committed
def LoadBrushSet(filepath, filename):
for file in os.listdir(filepath):
path = (filepath + file)
Dan Grauer
committed
#get folder name
(f1, f2) = os.path.split(filepath)
(f3, foldername) = os.path.split(f1)
Dan Grauer
committed
# filter files by extensions (filter images)
for i in ext_list:
if file.endswith(i):
print("file: ", file)
# create new texture
texture = bpy.data.textures.new(file, 'IMAGE')
texture.use_fake_user = fakeUser
print("texture: ", texture)
# now we need to load the image into data
image = bpy.data.images.load(path)
image.use_fake_user = fakeUser
# image.source = 'FILE' #default is FILE so can remove this
# image.filepath = path
print("image: ", image, " ", path)
print("texturename: ", texture.name)
# and assign the image to the texture
bpy.data.textures[texture.name].image = image
CoDEmanX
committed
print("Brush Set imported!")
Dan Grauer
committed
#---------------------------------------------#
Dan Grauer
committed
class BrushSetImporter(bpy.types.Operator):
Dan Grauer
committed
'''Load Brush Set'''
bl_idname = "import_image.brushset"
bl_label = "Import BrushSet"
filename = StringProperty(name="File Name", description="filepath", default="", maxlen=1024, options={'ANIMATABLE'}, subtype='NONE')
filepath = StringProperty(name="File Name", description="filepath", default="", maxlen=1024, options={'ANIMATABLE'}, subtype='NONE')
CoDEmanX
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'}
Dan Grauer
committed
#---------------------------------------------#
Dan Grauer
committed
def menu_func(self, context):
Dan Grauer
committed
import_name = ""
self.layout.operator(BrushSetImporter.bl_idname, text = "Brush Set").filename = import_name
Dan Grauer
committed
Dan Grauer
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'}
CoDEmanX
committed
Dan Grauer
committed
def draw(self, context):
CoDEmanX
committed
scn = context.scene
Dan Grauer
committed
layout = self.layout
column = layout.column(align=True)
column.label(text='Brush Directory:')
CoDEmanX
committed
column.prop(scn,'filepath')
Dan Grauer
committed
'''
#---------------------------------------------#
Dan Grauer
committed
CoDEmanX
committed
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_import.append(menu_func)
Dan Grauer
committed
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_file_import.remove(menu_func)
Dan Grauer
committed
if __name__ == "__main__":