3
from os import path as os_path, listdir as os_listdir
4
from bpy import path as bpy_path
6
# cross platform paths (since ms conform to / path ;) )
7
# maybe add utf8 replace to old ascii blender builtin
8
# // can be omitted for relative
10
path = path.strip().replace('\\','/')
11
if ('/') not in path : path = '//'+path
14
## test for existence of a file or a dir
16
if isfile(path) or isdir(path) : return True
19
## test for existence of a file
21
if os_path.isfile(path) : return True
22
# could be blender relative
23
path = bpy_path.abspath(path)
24
if os_path.isfile(path) : return True
27
## test for existence of a dir
29
if os_path.isdir(path) : return True
30
# could be blender relative
31
path = bpy_path.abspath(path)
32
if os_path.isdir(path) : return True
35
## returns a list of every absolute filepath
36
# to each file within the 'ext' extensions
37
# from a folder and its subfolders
38
def scanDir(path,ext='all') :
40
fields = os_listdir(path)
41
if ext != 'all' and type(ext) != list : ext = [ext]
43
if os_path.isfile(path + '/' + item) and (ext == 'all' or item.split('.')[-1] in ext) :
44
#print(' file %s'%item)
45
files.append(path + '/' + item)
46
elif os_path.isdir(path + '/' + item) :
47
print('folder %s/%s :'%(path,item))
48
files.extend(scanDir(path + '/' + item))
51
def saveOptions(operator_name, tokens, filename='last_run'):
52
target_path = os_path.join("operator", operator_name)
53
target_path = os_path.join("presets", target_path)
54
target_path = bpy.utils.user_resource('SCRIPTS',target_path,create=True)
56
filepath = os_path.join(target_path, filename) + ".py"
57
file_preset = open(filepath, 'w')
58
file_preset.write("import bpy\nop = bpy.context.active_operator\n\n")
59
properties_blacklist = bpy.types.Operator.bl_rna.properties.keys()
60
for key, value in tokens.items() :
61
if key not in properties_blacklist :
62
# convert thin wrapped sequences to simple lists to repr()
68
file_preset.write("op.%s = %r\n" % (key, value))