Palette linker
1.8.0 - feat: palette linker (beta), with pop-up from material stack dropdown - feat: palette name fuzzy match - code: add an open addon preference ops
This commit is contained in:
@@ -252,7 +252,9 @@ def remapping(value, leftMin, leftMax, rightMin, rightMax):
|
||||
# Convert the 0-1 range into a value in the right range.
|
||||
return rightMin + (valueScaled * rightSpan)
|
||||
|
||||
#### GP funcs
|
||||
# -----------------
|
||||
### GP funcs
|
||||
# -----------------
|
||||
|
||||
def get_gp_draw_plane(context, obj=None):
|
||||
''' return tuple with plane coordinate and normal
|
||||
@@ -546,15 +548,20 @@ def extrapolate_points_by_length(a,b, length):
|
||||
### Vector utils 2d
|
||||
# -----------------
|
||||
|
||||
|
||||
def is_vector_close(a, b, rel_tol=1e-03):
|
||||
'''compare Vector or sequence of value
|
||||
by default tolerance is set on 1e-03 (0.001)
|
||||
'''
|
||||
return all([math.isclose(i, j, rel_tol=rel_tol) for i, j in zip(a,b)])
|
||||
|
||||
def single_vector_length_2d(v):
|
||||
return sqrt((v[0] * v[0]) + (v[1] * v[1]))
|
||||
|
||||
|
||||
def vector_length_2d(A,B):
|
||||
''''take two Vector and return length'''
|
||||
return sqrt((A[0] - B[0])**2 + (A[1] - B[1])**2)
|
||||
|
||||
|
||||
def vector_length_coeff_2d(size, A, B):
|
||||
'''
|
||||
Calculate the vector lenght
|
||||
@@ -569,7 +576,7 @@ def vector_length_coeff_2d(size, A, B):
|
||||
|
||||
def cross_vector_coord_2d(foo, bar, size):
|
||||
'''Return the coord in space of a cross vector between the two point with specified size'''
|
||||
###middle location between 2 vector is calculated by adding the two vector and divide by two
|
||||
##middle location between 2 vector is calculated by adding the two vector and divide by two
|
||||
##mid = (foo + bar) / 2
|
||||
between = foo - bar
|
||||
#create a generic Up vector (on Y or Z)
|
||||
@@ -646,6 +653,17 @@ def get_addon_prefs():
|
||||
addon_prefs = preferences.addons[addon_name].preferences
|
||||
return (addon_prefs)
|
||||
|
||||
def open_addon_prefs():
|
||||
'''Open addon prefs windows with focus on current addon'''
|
||||
from .__init__ import bl_info
|
||||
wm = bpy.context.window_manager
|
||||
wm.addon_filter = 'All'
|
||||
if not 'COMMUNITY' in wm.addon_support: # reactivate community
|
||||
wm.addon_support = set([i for i in wm.addon_support] + ['COMMUNITY'])
|
||||
wm.addon_search = bl_info['name']
|
||||
bpy.context.preferences.active_section = 'ADDONS'
|
||||
bpy.ops.preferences.addon_expand(module=__package__)
|
||||
bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
|
||||
|
||||
def open_file(file_path) :
|
||||
'''Open filepath with default browser'''
|
||||
@@ -703,10 +721,24 @@ def detect_OS():
|
||||
print("Cannot detect OS, python 'sys.platform' give :", myOS)
|
||||
return None
|
||||
|
||||
def is_vector_close(a, b, rel_tol=1e-03):
|
||||
'''compare Vector or sequence of value
|
||||
by default tolerance is set on 1e-03 (0.001)'''
|
||||
return all([math.isclose(i, j, rel_tol=rel_tol) for i, j in zip(a,b)])
|
||||
def fuzzy_match(s1, s2, tol=0.8, case_sensitive=False):
|
||||
'''Tell if two strings are similar using a similarity ratio (0 to 1) value passed as third arg'''
|
||||
from difflib import SequenceMatcher
|
||||
# can also use difflib.get_close_matches(word, possibilities, n=3, cutoff=0.6)
|
||||
if case_sensitive:
|
||||
similarity = SequenceMatcher(None, s1, s2)
|
||||
else:
|
||||
similarity = SequenceMatcher(None, s1.lower(), s2.lower())
|
||||
return similarity.ratio() > tol
|
||||
|
||||
def fuzzy_match_ratio(s1, s2, case_sensitive=False):
|
||||
'''Tell how much two passed strings are similar 1.0 being exactly similar'''
|
||||
from difflib import SequenceMatcher
|
||||
if case_sensitive:
|
||||
similarity = SequenceMatcher(None, s1, s2)
|
||||
else:
|
||||
similarity = SequenceMatcher(None, s1.lower(), s2.lower())
|
||||
return similarity.ratio()
|
||||
|
||||
def convert_attr(Attr):
|
||||
'''Convert given value to a Json serializable format'''
|
||||
@@ -749,8 +781,9 @@ def show_message_box(_message = "", _title = "Message Box", _icon = 'INFO'):
|
||||
_message = [_message]
|
||||
bpy.context.window_manager.popup_menu(draw, title = _title, icon = _icon)
|
||||
|
||||
|
||||
# -----------------
|
||||
### UI utils
|
||||
# -----------------
|
||||
|
||||
## kmi draw for addon without delete button
|
||||
def draw_kmi(km, kmi, layout):
|
||||
@@ -857,17 +890,36 @@ def draw_kmi(km, kmi, layout):
|
||||
# draw_km(display_keymaps, kc, kmm, None, layout + 1)
|
||||
# layout.context_pointer_set("keymap", km)
|
||||
|
||||
# -----------------
|
||||
### linking utility
|
||||
# -----------------
|
||||
|
||||
"""
|
||||
def link_objects_in_blend(filepath, obj_name, link=True):
|
||||
'''Link an object by name from a file, if link is False, append instead of linking'''
|
||||
with bpy.data.libraries.load(filepath, link=link) as (data_from, data_to):
|
||||
data_to.objects = [o for o in data_from.objects if o == obj_name] # c.startswith(obj_name)
|
||||
return data_to.objects
|
||||
"""
|
||||
def link_objects_in_blend(filepath, obj_name_list, link=True):
|
||||
'''Link an object by name from a file, if link is False, append instead of linking'''
|
||||
if isinstance(obj_name_list, str):
|
||||
obj_name_list = [obj_name_list]
|
||||
with bpy.data.libraries.load(filepath, link=link) as (data_from, data_to):
|
||||
data_to.objects = [o for o in data_from.objects if o in obj_name_list]
|
||||
return data_to.objects
|
||||
|
||||
def check_materials_in_blend(filepath):
|
||||
'''Return a list of all material in remote blend file'''
|
||||
with bpy.data.libraries.load(filepath, link=False) as (data_from, data_to):
|
||||
l = [m for m in data_from.materials]
|
||||
return l
|
||||
|
||||
def check_objects_in_blend(filepath, avoid_camera=True):
|
||||
'''return a list of object name in file'''
|
||||
'''Return a list of object name in remote blend file'''
|
||||
with bpy.data.libraries.load(filepath, link=False) as (data_from, data_to):
|
||||
if avoid_camera:
|
||||
l = [o for o in data_from.objects if not 'camera' in o.lower()]
|
||||
l = [o for o in data_from.objects if not any(x in o.lower() for x in ('camera', 'draw_cam', 'obj_cam'))]
|
||||
else:
|
||||
l = [o for o in data_from.objects]
|
||||
return l
|
||||
Reference in New Issue
Block a user