[Bf-extensions-cvs] [c56b463d] master: Fix indentation, write into temp folder, and expose user prefs
Stephen Leger
noreply at git.blender.org
Thu Apr 18 03:06:24 CEST 2019
Commit: c56b463d06e6bd989019f2674775ec2cb511b823
Author: Stephen Leger
Date: Thu Apr 18 03:00:16 2019 +0200
Branches: master
https://developer.blender.org/rBAc56b463d06e6bd989019f2674775ec2cb511b823
Fix indentation, write into temp folder, and expose user prefs
===================================================================
M materials_library_vx/__init__.py
===================================================================
diff --git a/materials_library_vx/__init__.py b/materials_library_vx/__init__.py
index 01157def..17e3934e 100644
--- a/materials_library_vx/__init__.py
+++ b/materials_library_vx/__init__.py
@@ -19,16 +19,16 @@
# #####END GPL LICENSE BLOCK #####
bl_info = {
- "name": "Material Library",
- "author": "Mackraken (mackraken2023 at hotmail.com)",
- "version": (0, 5, 8),
- "blender": (2, 80, 0),
- "location": "Properties > Material",
- "description": "Material Library VX",
- "warning": "",
- "wiki_url": "https://sites.google.com/site/aleonserra/home/scripts/matlib-vx",
- "tracker_url": "",
- "category": "Material"}
+ "name": "Material Library",
+ "author": "Mackraken (mackraken2023 at hotmail.com)",
+ "version": (0, 5, 8),
+ "blender": (2, 80, 0),
+ "location": "Properties > Material",
+ "description": "Material Library VX",
+ "warning": "",
+ "wiki_url": "https://sites.google.com/site/aleonserra/home/scripts/matlib-vx",
+ "tracker_url": "",
+ "category": "Material"}
import bpy
@@ -52,100 +52,100 @@ dev = False
matlib_path = os.path.dirname(__file__)
if dev:
- print (30*"-")
- matlib_path = r"D:\Blender Foundation\Blender\2.72\scripts\addons\matlib"
+ print (30*"-")
+ matlib_path = r"D:\Blender Foundation\Blender\2.72\scripts\addons\matlib"
##debug print variables
def dd(*args, dodir=False):
- if dev:
- if dodir:
- print(dir(*args))
- print(*args)
+ if dev:
+ if dodir:
+ print(dir(*args))
+ print(*args)
#Regular Functions
def winpath(path):
- return path.replace("\\", "\\\\")
+ return path.replace("\\", "\\\\")
def update_search_index(self, context):
- search = self.search
- for i, it in enumerate(self.materials):
- if it.name==search:
- self.mat_index = i
- break
+ search = self.search
+ for i, it in enumerate(self.materials):
+ if it.name==search:
+ self.mat_index = i
+ break
def check_path(path):
- #isabs sometimes returns true on relpaths
- if path and os.path.exists(path) and os.path.isfile(path) and os.path.isabs(path):
- try:
- if bpy.data.filepath and bpy.path.relpath(bpy.data.filepath) == bpy.path.relpath(path):
- return False
- except:
- pass
- #paths are on different drives. No problem then
- return True
- return False
+ #isabs sometimes returns true on relpaths
+ if path and os.path.exists(path) and os.path.isfile(path) and os.path.isabs(path):
+ try:
+ if bpy.data.filepath and bpy.path.relpath(bpy.data.filepath) == bpy.path.relpath(path):
+ return False
+ except:
+ pass
+ #paths are on different drives. No problem then
+ return True
+ return False
def update_lib_index(self, context):
- self.load_library()
+ self.load_library()
def update_cat_index(self, context):
- dd("cat index:", self.current_category, self.filter)
+ dd("cat index:", self.current_category, self.filter)
- if self.filter:
- self.filter = True
+ if self.filter:
+ self.filter = True
def update_filter(self, context):
- dd("filter:", self.filter, self.cat_index, self.current_category)
-# index = self.cat_index
-#
-# if self.filter:
-# cat = self.current_category
-# else:
-# cat = ""
-#
-# self.current_library.filter = cat
- self.update_list()
+ dd("filter:", self.filter, self.cat_index, self.current_category)
+ # index = self.cat_index
+ #
+ # if self.filter:
+ # cat = self.current_category
+ # else:
+ # cat = ""
+ #
+ # self.current_library.filter = cat
+ self.update_list()
def check_index(collection, index):
- count = len(collection)
- return count>0 and index<count and index>=0
+ count = len(collection)
+ return count>0 and index<count and index>=0
def send_command(cmd, output="sendmat.py"):
bin = winpath(bpy.app.binary_path)
- scriptpath = winpath(os.path.join(matlib_path, output))
+ scriptpath = winpath(os.path.join(bpy.app.tempdir, output))
with open(scriptpath, "w") as f:
- f.write(cmd)
+ f.write(cmd)
import subprocess
if output == "createlib.py":
- code = subprocess.call([bin, "-b", "-P", scriptpath])
+ code = subprocess.call([bin, "-b", "-P", scriptpath])
else:
- libpath = winpath(bpy.context.scene.matlib.current_library.path)
- code = subprocess.call([bin, "-b", libpath, "-P", scriptpath])
+ libpath = winpath(bpy.context.scene.matlib.current_library.path)
+ code = subprocess.call([bin, "-b", libpath, "-P", scriptpath])
#code returns 0 if ok, 1 if not
return abs(code-1)
def list_materials(path, sort=False):
- list = []
- with bpy.data.libraries.load(path) as (data_from, data_to):
- for mat in data_from.materials:
- list.append(mat)
+ list = []
+ with bpy.data.libraries.load(path) as (data_from, data_to):
+ for mat in data_from.materials:
+ list.append(mat)
- if sort: list = sorted(list)
- return list
+ if sort: list = sorted(list)
+ return list
#category properties (none atm)
class EmptyGroup(PropertyGroup):
- pass
+ pass
# bpy.utils.register_class(EmptyGroup)
class matlibMaterials(PropertyGroup):
- category: StringProperty()
+ category: StringProperty()
# bpy.utils.register_class(matlibMaterials)
#bpy.types.Scene.matlib_categories = CollectionProperty(type=EmptyGroup)
@@ -153,17 +153,17 @@ class matlibMaterials(PropertyGroup):
### CATEGORIES
class Categories():
- #cats = bpy.context.scene.matlib.categories
+ #cats = bpy.context.scene.matlib.categories
- def __init__(self, cats):
- self.cats = cats
+ def __init__(self, cats):
+ self.cats = cats
- def save(self):
- scn = bpy.context.scene
- cats = set([cat.name for cat in self.cats])
- libpath = bpy.context.scene.matlib.current_library.path
+ def save(self):
+ scn = bpy.context.scene
+ cats = set([cat.name for cat in self.cats])
+ libpath = bpy.context.scene.matlib.current_library.path
- cmd = """
+ cmd = """
print(30*"+")
import bpy
if not hasattr(bpy.context.scene, "matlib_categories"):
@@ -175,19 +175,19 @@ cats = bpy.context.scene.matlib_categories
for cat in cats:
cats.remove(0)
"""
- for cat in cats:
- cmd += """
+ for cat in cats:
+ cmd += """
cat = cats.add()
cat.name = "%s" """ % cat.capitalize()
- cmd +='''
+ cmd +='''
bpy.ops.wm.save_mainfile(filepath="%s", check_existing=False, compress=True)''' % winpath(libpath)
- return send_command(cmd, "save_categories.py")
+ return send_command(cmd, "save_categories.py")
- def read(self, pull=True):
- #mandar a imprimir el listado
- catfile = winpath(os.path.join(matlib_path, "categories.txt"))
- cmd = """
+ def read(self, pull=True):
+ #mandar a imprimir el listado
+ catfile = winpath(os.path.join(matlib_path, "categories.txt"))
+ cmd = """
import bpy, json
class EmptyProps(bpy.types.PropertyGroup):
pass
@@ -203,61 +203,61 @@ for cat in bpy.context.scene.matlib_categories:
with open("%s", "w") as f:
f.write(json.dumps(cats, sort_keys=True, indent=4))
""" % catfile
- if pull: send_command(cmd)
+ if pull: send_command(cmd)
- #leer el fichero
- with open(catfile, "r") as f:
- cats = json.loads(f.read())
+ #leer el fichero
+ with open(catfile, "r") as f:
+ cats = json.loads(f.read())
- dd(cats)
+ dd(cats)
-# #refrescar categorias
-# for cat in self.cats:
-# self.cats.remove(0)
-#
-# for cat in cats:
-# item = self.cats.add()
-# item.name = cat
-#
- return cats
-
- def view(self):
- for cat in self.cats:
- dd(cat.name)
-
- def add(self, name):
- if name and name not in [item.name for item in self.cats]:
- name = name.strip().capitalize()
- item = self.cats.add()
- item.name = name
- if self.save():
- dd(name, "added")
- return True
- else:
- dd("duplicated?")
+ # #refrescar categorias
+ # for cat in self.cats:
+ # self.cats.remove(0)
+ #
+ # for cat in cats:
+ # item = self.cats.add()
+ # item.name = cat
+ #
+ return cats
+
+ def view(self):
+ for cat in self.cats:
+ dd(cat.name)
+
+ def add(self, name):
+ if name and name not in [item.name for item in self.cats]:
+ name = name.strip().capitalize()
+ item = self.cats.add()
+ item.name = name
+ if self.save():
+ dd(name, "added")
+ return True
+ else:
+ dd("duplicated?")
- def remove(self, index):
- self.cats.remove(index)
- self.save()
+ def remove(self, index):
+ self.cats.remove(index)
+ self.save()
class Library():
- def __init__(self, matlib_path, name):
- self.name = name
- self.path = os.path.join(matlib_path, name)
-# @property
-# def default(self):
-# return self.name == default_library
+ def __init__(self, matlib_path, name):
+ self.name = name
+ self.path = os.path.join(matlib_path, name)
+ # @property
+ # def default(self):
+ # return self.name == default_library
- @property
- def shortname(self):
-# if self.default:
-# return "Default Library"
- return bpy.path.display_name(self.name).title()
+ @property
+ def shortname(self):
+ # if self.default:
+ # return "Default Library"
+ return bpy.path.display_name(self.name).title()
- def __repr__(self):
- return str(type(self).__name__) + "('" + self.name + "')"
+ def __repr__(self):
+ return str(type(self).__name__) + "('" + self.name + "')"
#bpy.utils.register_class(Library)
@@ -280,184 +280,184 @@ libraries = []
### MATLIB CLASS
class matlibProperties(PropertyGroup):
- #MATLIB PROPERTIES
-
- #libraries are read from the xml
- lib_index: IntProperty(min = -1, default = 2, update=update_lib_index)
- all_materials: CollectionProperty(type = matlibMaterials)
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list