picker on visible

gpv2
Pullusb 2021-07-29 11:20:43 +02:00
parent a218aefd10
commit 985e395beb
3 changed files with 30 additions and 12 deletions

View File

@ -5,7 +5,7 @@
- feat: Namespace upgrade
- support pseudo group naming
- add group and indent button
- feat: Fill tool shortcut for material color picker (from closest stroke)
- feat: Fill tool shortcut for material color picker (from closest visible stroke)
- `S` : get material closest *fill* stroke
- `Àlt+S` : get closest stroke (fill or stroke)

View File

@ -139,16 +139,19 @@ class GPTB_OT_layer_name_build(Operator):
return {"FINISHED"}
def grp_toggle(l):
def grp_toggle(l, mode='TOGGLE'):
'''take mode in (TOGGLE, GROUP, UNGROUP) '''
grp_item_id = ' - '
res = re.search(r'^(\s{1,3}-\s{0,3})(.*)', l.info)
if not res:
# add group prefix after stripping all space and dash
if not res and mode in ('TOGGLE', 'GROUP'):
# No gpr : add group prefix after stripping all space and dash
l.info = grp_item_id + l.info.lstrip(' -')
else:
# delete group prefix
elif res and mode in ('TOGGLE', 'UNGROUP'):
# found : delete group prefix
l.info = res.group(2)
class GPTB_OT_layer_group_toggle(Operator):
bl_idname = "gp.layer_group_toggle"
bl_label = "Group Toggle"
@ -186,18 +189,26 @@ class GPTB_OT_layer_new_group(Operator):
if not act:
self.report({'ERROR'}, 'no layer active')
return {"CANCELLED"}
res = re.search(PATTERN, act.info)
if not res:
self.report({'ERROR'}, 'Could not create a group name, create a layer manually')
return {"CANCELLED"}
name = res.group('name')
name = res.group('name').strip(' -')
if not name:
self.report({'ERROR'}, f'No name found in {act.info}')
return {"CANCELLED"}
if name in [l.info for l in gpl]:
if name in [l.info.strip(' -') for l in gpl]:
self.report({'WARNING'}, f'Name already exists: {act.info}')
return {"FINISHED"}
gpl.new(name, set_active=False)
grp_toggle(act, mode='GROUP')
n = gpl.new(name, set_active=False)
n.use_onion_skinning = n.use_lights = False
n.hide = True
n.opacity = 0
return {"FINISHED"}
@ -479,14 +490,21 @@ def obj_layer_name_callback():
if not ob.data.layers.active:
return
## Set selection to active object ot avoid un-sync selection on Layers stack
## (happen when an objet is selected but not active with 'lock object mode')
for l in ob.data.layers:
l.select = l == ob.data.layers.active
res = re.search(PATTERN, ob.data.layers.active.info)
res = re.search(PATTERN, ob.data.layers.active.info.strip())
if not res:
return
if not res.group('name'):
return
print('grp:', res.group('grp'))
print('tag:', res.group('tag'))
print('name:', res.group('name'))
print('sfix:', res.group('sfix'))
print('inc:', res.group('inc'))
bpy.context.scene.gptoolprops['layer_name'] = res.group('name')
@persistent

View File

@ -77,7 +77,7 @@ class GP_OT_pick_closest_material(Operator):
if self.gp.use_multiedit:
for l in self.gp.layers:
if l.lock or l.hide:
if l.hide:# l.lock or
continue
for f in l.frames:
if not f.select:
@ -88,7 +88,7 @@ class GP_OT_pick_closest_material(Operator):
else:
# [s for l in self.gp.layers if not l.lock and not l.hide for s in l.active_frame.stokes]
for l in self.gp.layers:
if l.lock or l.hide or not l.active_frame:
if l.hide or not l.active_frame:# l.lock or
continue
for s in l.active_frame.strokes:
self.stroke_list.append(s)