Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
f0099eb9
Commit
f0099eb9
authored
4 years ago
by
CansecoGPC
Browse files
Options
Downloads
Patches
Plain Diff
Promote Import BrushSet
parent
aea05413
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
io_import_BrushSet.py
+181
-0
181 additions, 0 deletions
io_import_BrushSet.py
with
181 additions
and
0 deletions
io_import_BrushSet.py
0 → 100644
+
181
−
0
View file @
f0099eb9
# ##### BEGIN GPL LICENSE BLOCK #####
#
# 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.
#
# 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.
#
# 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.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8-80 compliant>
#---------------------------------------------#
# todo
#---------------------------------------------#
'''
- add file selection for single and multiple files
- option to enable/disable fake users
'''
#---------------------------------------------#
import
bpy
import
os
from
bpy.props
import
*
# addon description
bl_info
=
{
"
name
"
:
"
Import BrushSet
"
,
"
author
"
:
"
Daniel Grauer (kromar), CansecoGPC
"
,
"
version
"
:
(
1
,
2
,
2
),
"
blender
"
:
(
2
,
80
,
0
),
"
location
"
:
"
File > Import > BrushSet
"
,
"
description
"
:
"
Imports all image files from a folder.
"
,
"
warning
"
:
''
,
# used for warning icon and text in addons panel
"
doc_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/
"
,
"
category
"
:
"
Import-Export
"
,
}
#---------------------------------------------#
# 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
def
LoadBrushSet
(
filepath
,
filename
):
for
file
in
os
.
listdir
(
filepath
):
path
=
(
filepath
+
file
)
# get folder name
(
f1
,
f2
)
=
os
.
path
.
split
(
filepath
)
(
f3
,
foldername
)
=
os
.
path
.
split
(
f1
)
# filter files by extensions (filter images)
if
any
(
file
.
lower
().
endswith
(
ext
)
for
ext
in
ext_list
):
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
print
(
"
Brush Set imported!
"
)
#---------------------------------------------#
class
BrushSetImporter
(
bpy
.
types
.
Operator
):
'''
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
'
)
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
'
}
#---------------------------------------------#
def
menu_func
(
self
,
context
):
# clear the default name for import
import_name
=
""
self
.
layout
.
operator
(
BrushSetImporter
.
bl_idname
,
text
=
"
Brush Set
"
).
filename
=
import_name
#---------------------------------------------#
# 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
'
}
def draw(self, context):
scn = context.scene
layout = self.layout
column = layout.column(align=True)
column.label(text=
'
Brush Directory:
'
)
column.prop(scn,
'
filepath
'
)
'''
#---------------------------------------------#
classes
=
(
BrushSetImporter
,
)
def
register
():
from
bpy.utils
import
register_class
for
cls
in
classes
:
register_class
(
cls
)
bpy
.
types
.
TOPBAR_MT_file_import
.
append
(
menu_func
)
def
unregister
():
from
bpy.utils
import
unregister_class
for
cls
in
reversed
(
classes
):
unregister_class
(
cls
)
bpy
.
types
.
TOPBAR_MT_file_import
.
remove
(
menu_func
)
if
__name__
==
"
__main__
"
:
register
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment