12 Commits
30 changed files with 465 additions and 743 deletions
-22
View File
@@ -1,27 +1,5 @@
# Changelog # Changelog
3.3.5
- added: copy paste option to copy only existing frame without baking the whole move
3.3.4
- fixed: Error when trying to load addon in 4.3.0+ (prevent loading without error, print about incompatibility in console)
3.3.3
- added: list collections visibility conflict from search menu with dev extras (backported from gpv3)
3.3.2
- added: fix cursor follow and add optional target object (backported from gpv3)
3.3.1
- added: improve file checker and visibility conflict feature (backported from gpv3)
-- GPv2 code - Above this line, version is separated from 4.3+ version (using GPv3) --
3.3.0 3.3.0
- added: `Move Material To Layer` has now option to copy instead of moving in pop-up menu. - added: `Move Material To Layer` has now option to copy instead of moving in pop-up menu.
+4 -4
View File
@@ -9,7 +9,7 @@ from bpy.props import (FloatProperty,
## copied from OP_key_duplicate_send ## copied from OP_key_duplicate_send
def get_layer_list(self, context): def get_layer_list(self, context):
'''return (identifier, name, description) of enum content''' '''return (identifier, name, description) of enum content'''
return [(l.info, l.info, '') for l in context.object.data.layers if l != context.object.data.layers.active] return [(l.name, l.name, '') for l in context.object.data.layers if l != context.object.data.layers.active]
class GP_OT_create_empty_frames(bpy.types.Operator): class GP_OT_create_empty_frames(bpy.types.Operator):
bl_idname = "gp.create_empty_frames" bl_idname = "gp.create_empty_frames"
@@ -57,7 +57,7 @@ class GP_OT_create_empty_frames(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.active_object is not None and context.active_object.type == 'GPENCIL' return context.active_object is not None and context.active_object.type == 'GREASEPENCIL'
def invoke(self, context, event): def invoke(self, context, event):
# Possible preset with shortcut # Possible preset with shortcut
@@ -113,7 +113,7 @@ class GP_OT_create_empty_frames(bpy.types.Operator):
if not self.layers_enum: if not self.layers_enum:
self.report({'ERROR'}, f"No chosen layers, aborted") self.report({'ERROR'}, f"No chosen layers, aborted")
return {'CANCELLED'} return {'CANCELLED'}
tgt_layers = [l for l in gpl if l.info == self.layers_enum] tgt_layers = [l for l in gpl if l.name == self.layers_enum]
elif self.targeted_layers == 'NUMBER': elif self.targeted_layers == 'NUMBER':
if self.number == 0: if self.number == 0:
@@ -168,7 +168,7 @@ class GP_OT_create_empty_frames(bpy.types.Operator):
gpl.update() gpl.update()
if fct: if fct:
self.report({'INFO'}, f"{fct} frame created on layer {gpl.active.info}") self.report({'INFO'}, f"{fct} frame created on layer {gpl.active.name}")
else: else:
self.report({'WARNING'}, f"No frames to create !") self.report({'WARNING'}, f"No frames to create !")
+40 -37
View File
@@ -53,11 +53,14 @@ def create_gap_stroke(f, ob, tol=10, mat_id=None):
encounter = defaultdict(list) encounter = defaultdict(list)
plist = [] plist = []
matrix = ob.matrix_world matrix = ob.matrix_world
for s in f.strokes:#add first and last for s in f.drawing.strokes: #add first and last
smat = ob.material_slots[s.material_index].material smat = ob.material_slots[s.material_index].material
if not smat:continue#no material on line if not smat:
if smat.grease_pencil.show_fill:continue# skip fill lines -> #smat.grease_pencil.show_stroke continue #no material on line
if len(s.points) < 2:continue#avoid 0 or 1 points if smat.grease_pencil.show_fill:
continue # skip fill lines -> #smat.grease_pencil.show_stroke
if len(s.points) < 2:
continue #avoid 0 or 1 points
plist.append(s.points[0]) plist.append(s.points[0])
plist.append(s.points[-1]) plist.append(s.points[-1])
# plist.extend([s.points[0], s.points[-1])# is extend faster ? # plist.extend([s.points[0], s.points[-1])# is extend faster ?
@@ -70,7 +73,7 @@ def create_gap_stroke(f, ob, tol=10, mat_id=None):
for op in plist:#other points for op in plist:#other points
if p == op:# print('same point') if p == op:# print('same point')
continue continue
gap2d = vector_length_2d(location_to_region(matrix @ p.co), location_to_region(matrix @ op.co)) gap2d = vector_length_2d(location_to_region(matrix @ p.position), location_to_region(matrix @ op.position))
# print('gap2d: ', gap2d) # print('gap2d: ', gap2d)
if gap2d > tol: if gap2d > tol:
continue continue
@@ -102,16 +105,16 @@ def create_gap_stroke(f, ob, tol=10, mat_id=None):
encounter[p].append(op) encounter[p].append(op)
simple_draw_gp_stroke([p.co, op.co], f, width = 2, mat_id = mat_id) simple_draw_gp_stroke([p.position, op.position], f, width = 2, mat_id = mat_id)
ctl += 1 ctl += 1
print(f'{ctl} line created') print(f'{ctl} line created')
##test_call: #create_gap_stroke(C.object.data.layers.active.active_frame, C.object, mat_id=C.object.active_material_index) ##test_call: #create_gap_stroke(C.object.data.layers.active.current_frame(), C.object, mat_id=C.object.active_material_index)
def create_closing_line(tolerance=0.2): def create_closing_line(tolerance=0.2):
for ob in bpy.context.selected_objects: for ob in bpy.context.selected_objects:
if ob.type != 'GPENCIL': if ob.type != 'GREASEPENCIL':
continue continue
mat_id = get_closeline_mat(ob)# get a the closing material mat_id = get_closeline_mat(ob)# get a the closing material
@@ -128,7 +131,7 @@ def create_closing_line(tolerance=0.2):
## filter on selected ## filter on selected
if not l.select:continue# comment this line for all if not l.select:continue# comment this line for all
# for f in l.frames:#not all for now # for f in l.frames:#not all for now
f = l.active_frame f = l.current_frame()
## create gap stroke ## create gap stroke
create_gap_stroke(f, ob, tol=tolerance, mat_id=mat_id) create_gap_stroke(f, ob, tol=tolerance, mat_id=mat_id)
@@ -143,9 +146,9 @@ def is_deviating_by(s, deviation=0.75):
pb = s.points[-2] pb = s.points[-2]
pc = s.points[-3] pc = s.points[-3]
a = location_to_region(pa.co) a = location_to_region(pa.position)
b = location_to_region(pb.co) b = location_to_region(pb.position)
c = location_to_region(pc.co) c = location_to_region(pc.position)
#cb-> compare angle with ba-> #cb-> compare angle with ba->
angle = (b-c).angle(a-b) angle = (b-c).angle(a-b)
@@ -158,16 +161,16 @@ def extend_stroke_tips(s,f,ob,length, mat_id):
'''extend line boundary by given length''' '''extend line boundary by given length'''
for id_pair in [ [1,0], [-2,-1] ]:# start and end pair for id_pair in [ [1,0], [-2,-1] ]:# start and end pair
## 2D mode ## 2D mode
# a = location_to_region(ob.matrix_world @ s.points[id_pair[0]].co) # a = location_to_region(ob.matrix_world @ s.points[id_pair[0]].position)
# b_loc = ob.matrix_world @ s.points[id_pair[1]].co # b_loc = ob.matrix_world @ s.points[id_pair[1]].position
# b = location_to_region(b_loc) # b = location_to_region(b_loc)
# c = extrapolate_points_by_length(a,b,length)#print(vector_length_2d(b,c)) # c = extrapolate_points_by_length(a,b,length)#print(vector_length_2d(b,c))
# c_loc = region_to_location(c, b_loc) # c_loc = region_to_location(c, b_loc)
# simple_draw_gp_stroke([ob.matrix_world.inverted() @ b_loc, ob.matrix_world.inverted() @ c_loc], f, width=2, mat_id=mat_id) # simple_draw_gp_stroke([ob.matrix_world.inverted() @ b_loc, ob.matrix_world.inverted() @ c_loc], f, width=2, mat_id=mat_id)
## 3D ## 3D
a = s.points[id_pair[0]].co# ob.matrix_world @ a = s.points[id_pair[0]].position# ob.matrix_world @
b = s.points[id_pair[1]].co# ob.matrix_world @ b = s.points[id_pair[1]].position# ob.matrix_world @
c = extrapolate_points_by_length(a,b,length)#print(vector_length(b,c)) c = extrapolate_points_by_length(a,b,length)#print(vector_length(b,c))
simple_draw_gp_stroke([b,c], f, width=2, mat_id=mat_id) simple_draw_gp_stroke([b,c], f, width=2, mat_id=mat_id)
@@ -188,15 +191,15 @@ def change_extension_length(ob, strokelist, length, selected=False):
## Change length of current length to designated ## Change length of current length to designated
# Vector point A to point B (direction), push point B in this direction # Vector point A to point B (direction), push point B in this direction
a = s.points[-2].co a = s.points[-2].position
bp = s.points[-1]#end-point bp = s.points[-1]#end-point
b = bp.co b = bp.position
ab = b - a ab = b - a
if not ab: if not ab:
continue continue
# new pos of B is A + new length in the AB direction # new pos of B is A + new length in the AB direction
newb = a + (ab.normalized() * length) newb = a + (ab.normalized() * length)
bp.co = newb bp.position = newb
ct += 1 ct += 1
return ct return ct
@@ -210,14 +213,14 @@ def extend_all_strokes_tips(ob, frame, length=10, selected=False):
return return
# TODO need custom filters or go in GP refine strokes... # TODO need custom filters or go in GP refine strokes...
# frame = ob.data.layers.active.active_frame # frame = ob.data.layers.active.current_frame()
if not frame: return if not frame: return
ct = 0 ct = 0
#TODO need to delete previous closing lines on frame before launching #TODO need to delete previous closing lines on frame before launching
# iterate in a copy of stroke list to avoid growing frame.strokes as we loop in ! # iterate in a copy of stroke list to avoid growing frame.drawing.strokes as we loop in !
for s in list(frame.strokes): for s in list(frame.drawing.strokes):
if s.material_index == mat_id:#is a closeline if s.material_index == mat_id:#is a closeline
continue continue
if len(s.points) < 2:#not enough point to evaluate if len(s.points) < 2:#not enough point to evaluate
@@ -241,7 +244,7 @@ class GPSTK_OT_extend_lines(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.active_object is not None and context.active_object.type == 'GPENCIL' return context.active_object is not None and context.active_object.type == 'GREASEPENCIL'
# mode : bpy.props.StringProperty( # mode : bpy.props.StringProperty(
# name="mode", description="Set mode for operator", default="render", maxlen=0, subtype='NONE', options={'ANIMATABLE'}) # name="mode", description="Set mode for operator", default="render", maxlen=0, subtype='NONE', options={'ANIMATABLE'})
@@ -277,14 +280,14 @@ class GPSTK_OT_extend_lines(bpy.types.Operator):
elif self.layer_tgt == 'ALL_VISIBLE': elif self.layer_tgt == 'ALL_VISIBLE':
lays = [l for l in ob.data.layers if not l.hide] lays = [l for l in ob.data.layers if not l.hide]
else: else:
lays = [l for l in ob.data.layers if not any(x in l.info for x in ('spot', 'colo'))] lays = [l for l in ob.data.layers if not any(x in l.name for x in ('spot', 'colo'))]
fct = 0 fct = 0
for l in lays: for l in lays:
if not l.active_frame: if not l.current_frame():
print(f'{l.info} has no active frame') print(f'{l.name} has no active frame')
continue continue
fct += extend_all_strokes_tips(ob, l.active_frame, length = self.length, selected = self.selected) fct += extend_all_strokes_tips(ob, l.current_frame(), length = self.length, selected = self.selected)
if not fct: if not fct:
mess = "No strokes extended... see console" mess = "No strokes extended... see console"
@@ -306,7 +309,7 @@ class GPSTK_OT_change_closeline_length(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.active_object is not None and context.active_object.type == 'GPENCIL' return context.active_object is not None and context.active_object.type == 'GREASEPENCIL'
layer_tgt : bpy.props.EnumProperty( layer_tgt : bpy.props.EnumProperty(
name="Extend layers", description="Choose which layer to target", name="Extend layers", description="Choose which layer to target",
@@ -338,14 +341,14 @@ class GPSTK_OT_change_closeline_length(bpy.types.Operator):
elif self.layer_tgt == 'ALL_VISIBLE': elif self.layer_tgt == 'ALL_VISIBLE':
lays = [l for l in ob.data.layers if not l.hide] lays = [l for l in ob.data.layers if not l.hide]
else: else:
lays = [l for l in ob.data.layers if not any(x in l.info for x in ('spot', 'colo'))] lays = [l for l in ob.data.layers if not any(x in l.name for x in ('spot', 'colo'))]
fct = 0 fct = 0
for l in lays: for l in lays:
if not l.active_frame: if not l.current_frame():
print(f'{l.info} has no active frame') print(f'{l.name} has no active frame')
continue continue
fct += change_extension_length(ob, [s for s in l.active_frame.strokes], length = self.length, selected = self.selected) fct += change_extension_length(ob, [s for s in l.current_frame().drawing.strokes], length = self.length, selected = self.selected)
if not fct: if not fct:
mess = "No extension modified... see console" mess = "No extension modified... see console"
@@ -367,15 +370,15 @@ class GPSTK_OT_comma_finder(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.active_object is not None and context.active_object.type == 'GPENCIL' return context.active_object is not None and context.active_object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
ct = 0 ct = 0
ob = context.object ob = context.object
lays = [l for l in ob.data.layers if not l.hide and not l.lock] lays = [l for l in ob.data.layers if not l.hide and not l.lock]
for l in lays: for l in lays:
if not l.active_frame:continue if not l.current_frame():continue
for s in l.active_frame.strokes: for s in l.current_frame().drawing.strokes:
if is_deviating_by(s, context.scene.gpcolor_props.deviation_tolerance): if is_deviating_by(s, context.scene.gpcolor_props.deviation_tolerance):
ct+=1 ct+=1
@@ -397,7 +400,7 @@ class GPSTK_PT_line_closer_panel(bpy.types.Panel):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return (context.object is not None)# and context.object.type == 'GPENCIL' return (context.object is not None)# and context.object.type == 'GREASEPENCIL'
## draw stuff inside the header (place before main label) ## draw stuff inside the header (place before main label)
# def draw_header(self, context): # def draw_header(self, context):
@@ -414,7 +417,7 @@ class GPSTK_PT_line_closer_panel(bpy.types.Panel):
layout.operator("gp.extend_close_lines", icon = 'SNAP_MIDPOINT') layout.operator("gp.extend_close_lines", icon = 'SNAP_MIDPOINT')
#diplay closeline visibility #diplay closeline visibility
if context.object.type == 'GPENCIL' and context.object.data.materials.get('closeline'): if context.object.type == 'GREASEPENCIL' and context.object.data.materials.get('closeline'):
row=layout.row() row=layout.row()
row.prop(context.object.data.materials['closeline'].grease_pencil, 'hide', text='Stop lines') row.prop(context.object.data.materials['closeline'].grease_pencil, 'hide', text='Stop lines')
row.operator("gp.change_close_lines_extension", text='Length', icon = 'DRIVER_DISTANCE') row.operator("gp.change_close_lines_extension", text='Length', icon = 'DRIVER_DISTANCE')
+6 -6
View File
@@ -27,7 +27,7 @@ class GPTB_OT_load_brushes(bpy.types.Operator, ImportHelper):
# @classmethod # @classmethod
# def poll(cls, context): # def poll(cls, context):
# return context.object and context.object.type == 'GPENCIL' # return context.object and context.object.type == 'GREASEPENCIL'
filename_ext = '.blend' filename_ext = '.blend'
@@ -58,7 +58,7 @@ class GPTB_OT_brush_set(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.mode == 'PAINT_GPENCIL' return context.object and context.mode == 'PAINT_GREASE_PENCIL'
def execute(self, context): def execute(self, context):
brush = bpy.data.brushes.get(self.brush_name) brush = bpy.data.brushes.get(self.brush_name)
@@ -72,12 +72,12 @@ class GPTB_OT_brush_set(bpy.types.Operator):
def load_brush_ui(self, context): def load_brush_ui(self, context):
prefs = get_addon_prefs() prefs = get_addon_prefs()
if context.mode == 'PAINT_GPENCIL': if context.mode == 'PAINT_GREASE_PENCIL':
self.layout.operator('gp.load_brushes', icon='KEYTYPE_JITTER_VEC').filepath = prefs.brush_path self.layout.operator('gp.load_brushes', icon='KEYTYPE_JITTER_VEC').filepath = prefs.brush_path
def load_brush_top_bar_ui(self, context): def load_brush_top_bar_ui(self, context):
prefs = get_addon_prefs() prefs = get_addon_prefs()
if context.mode == 'PAINT_GPENCIL': if context.mode == 'PAINT_GREASE_PENCIL':
self.layout.operator('gp.load_brushes').filepath = prefs.brush_path self.layout.operator('gp.load_brushes').filepath = prefs.brush_path
classes = ( classes = (
@@ -89,12 +89,12 @@ def register():
for cl in classes: for cl in classes:
bpy.utils.register_class(cl) bpy.utils.register_class(cl)
bpy.types.VIEW3D_MT_brush_gpencil_context_menu.append(load_brush_ui) bpy.types.VIEW3D_MT_brush_context_menu.append(load_brush_ui)
bpy.types.VIEW3D_HT_tool_header.append(load_brush_top_bar_ui) bpy.types.VIEW3D_HT_tool_header.append(load_brush_top_bar_ui)
def unregister(): def unregister():
bpy.types.VIEW3D_HT_tool_header.remove(load_brush_top_bar_ui) bpy.types.VIEW3D_HT_tool_header.remove(load_brush_top_bar_ui)
bpy.types.VIEW3D_MT_brush_gpencil_context_menu.remove(load_brush_ui) bpy.types.VIEW3D_MT_brush_context_menu.remove(load_brush_ui)
for cl in reversed(classes): for cl in reversed(classes):
bpy.utils.unregister_class(cl) bpy.utils.unregister_class(cl)
+30 -33
View File
@@ -169,13 +169,13 @@ def copycut_strokes(layers=None, copy=True, keep_empty=True):
stroke_list = [] # one stroke list for all layers. stroke_list = [] # one stroke list for all layers.
for l in layers: for l in layers:
f = l.active_frame f = l.current_frame()
if f: # active frame can be None if f: # active frame can be None
if not copy: if not copy:
staylist = [] # init part of strokes that must survive on this layer staylist = [] # init part of strokes that must survive on this layer
for s in f.strokes: for s in f.drawing.strokes:
if s.select: if s.select:
# separate in multiple stroke if parts of the strokes a selected. # separate in multiple stroke if parts of the strokes a selected.
sel = [i for i, p in enumerate(s.points) if p.select] sel = [i for i, p in enumerate(s.points) if p.select]
@@ -192,7 +192,7 @@ def copycut_strokes(layers=None, copy=True, keep_empty=True):
if not copy: if not copy:
maxindex = len(s.points)-1 maxindex = len(s.points)-1
if len(substrokes) == maxindex+1: # if only one substroke, then it's the full stroke if len(substrokes) == maxindex+1: # if only one substroke, then it's the full stroke
f.strokes.remove(s) f.drawing.strokes.remove(s)
else: else:
neg = [i for i, p in enumerate(s.points) if not p.select] neg = [i for i, p in enumerate(s.points) if not p.select]
@@ -217,14 +217,14 @@ def copycut_strokes(layers=None, copy=True, keep_empty=True):
stroke_list.append(dump_gp_stroke(s,l)) stroke_list.append(dump_gp_stroke(s,l))
#delete stroke on the fly #delete stroke on the fly
if not copy: if not copy:
f.strokes.remove(s) f.drawing.strokes.remove(s)
''' '''
if not copy: if not copy:
# delete all selected strokes... # delete all selected strokes...
for s in f.strokes: for s in f.drawing.strokes:
if s.select: if s.select:
f.strokes.remove(s) f.drawing.strokes.remove(s)
# ...recreate these uncutted ones # ...recreate these uncutted ones
#pprint(staylist) #pprint(staylist)
if staylist: if staylist:
@@ -234,7 +234,7 @@ def copycut_strokes(layers=None, copy=True, keep_empty=True):
#if nothing left on the frame choose to leave an empty frame or delete it (let previous frame appear) #if nothing left on the frame choose to leave an empty frame or delete it (let previous frame appear)
if not copy and not keep_empty:# if not copy and not keep_empty:#
if not len(f.strokes): if not len(f.drawing.strokes):
l.frames.remove(f) l.frames.remove(f)
@@ -268,12 +268,12 @@ def copy_all_strokes(layers=None):
stroke_list = []# one stroke list for all layers. stroke_list = []# one stroke list for all layers.
for l in layers: for l in layers:
f = l.active_frame f = l.current_frame()
if not f: if not f:
continue# active frame can be None continue# active frame can be None
for s in f.strokes: for s in f.drawing.strokes:
## full stroke version ## full stroke version
# if s.select: # if s.select:
stroke_list.append(dump_gp_stroke_range(s, None, l, obj)) stroke_list.append(dump_gp_stroke_range(s, None, l, obj))
@@ -308,12 +308,12 @@ def copy_all_strokes_in_frame(frame=None, layers=None, obj=None,
stroke_list = [] stroke_list = []
for l in layers: for l in layers:
f = l.active_frame f = l.current_frame()
if not f: if not f:
continue# active frame can be None continue# active frame can be None
for s in f.strokes: for s in f.drawing.strokes:
## full stroke version ## full stroke version
# if s.select: # if s.select:
# send index of all points to get the whole stroke with "range" # send index of all points to get the whole stroke with "range"
@@ -326,7 +326,7 @@ def copy_all_strokes_in_frame(frame=None, layers=None, obj=None,
def add_stroke(s, frame, layer, obj, select=False): def add_stroke(s, frame, layer, obj, select=False):
'''add stroke on a given frame, (layer is for parentage setting)''' '''add stroke on a given frame, (layer is for parentage setting)'''
# print(3*'-',s) # print(3*'-',s)
ns = frame.strokes.new() ns = frame.drawing.strokes.new()
for att, val in s.items(): for att, val in s.items():
if att not in ('points'): if att not in ('points'):
@@ -347,7 +347,7 @@ def add_stroke(s, frame, layer, obj, select=False):
for k, v in pt.items(): for k, v in pt.items():
if k == 'co': if k == 'co':
setattr(ns.points[i], k, v) setattr(ns.points[i], k, v)
ns.points[i].co = ob_mat_inv @ mat @ ns.points[i].co # invert of object * invert of layer * coordinate ns.points[i].position = ob_mat_inv @ mat @ ns.points[i].position # invert of object * invert of layer * coordinate
else: else:
setattr(ns.points[i], k, v) setattr(ns.points[i], k, v)
if select: if select:
@@ -358,7 +358,7 @@ def add_stroke(s, frame, layer, obj, select=False):
for k, v in pt.items(): for k, v in pt.items():
if k == 'co': if k == 'co':
setattr(ns.points[i], k, v) setattr(ns.points[i], k, v)
ns.points[i].co = ob_mat_inv @ ns.points[i].co# invert of object * coordinate ns.points[i].position = ob_mat_inv @ ns.points[i].position# invert of object * coordinate
else: else:
setattr(ns.points[i], k, v) setattr(ns.points[i], k, v)
if select: if select:
@@ -389,7 +389,7 @@ def add_multiple_strokes(stroke_list, layer=None, use_current_frame=True, select
fnum = scene.frame_current fnum = scene.frame_current
target_frame = False target_frame = False
act = layer.active_frame act = layer.current_frame()
## set frame if needed ## set frame if needed
if act: if act:
if use_current_frame or act.frame_number == fnum: if use_current_frame or act.frame_number == fnum:
@@ -423,10 +423,10 @@ class GPCLIP_OT_copy_strokes(bpy.types.Operator):
#copy = bpy.props.BoolProperty(default=True) #copy = bpy.props.BoolProperty(default=True)
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
# if not context.object or not context.object.type == 'GPENCIL': # if not context.object or not context.object.type == 'GREASEPENCIL':
# self.report({'ERROR'},'No GP object selected') # self.report({'ERROR'},'No GP object selected')
# return {"CANCELLED"} # return {"CANCELLED"}
@@ -452,10 +452,10 @@ class GPCLIP_OT_cut_strokes(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
# if not context.object or not context.object.type == 'GPENCIL': # if not context.object or not context.object.type == 'GREASEPENCIL':
# self.report({'ERROR'},'No GP object selected') # self.report({'ERROR'},'No GP object selected')
# return {"CANCELLED"} # return {"CANCELLED"}
@@ -477,10 +477,10 @@ class GPCLIP_OT_paste_strokes(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
# if not context.object or not context.object.type == 'GPENCIL': # if not context.object or not context.object.type == 'GREASEPENCIL':
# self.report({'ERROR'},'No GP object selected to paste on') # self.report({'ERROR'},'No GP object selected to paste on')
# return {"CANCELLED"} # return {"CANCELLED"}
@@ -510,10 +510,7 @@ class GPCLIP_OT_copy_multi_strokes(bpy.types.Operator):
#copy = bpy.props.BoolProperty(default=True) #copy = bpy.props.BoolProperty(default=True)
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
bake_moves : bpy.props.BoolProperty(name='Bake Move', default=True,
description='Copy every frame where object has moved, else copy only existing frames)')
pressure : bpy.props.BoolProperty(name='pressure', default=True, pressure : bpy.props.BoolProperty(name='pressure', default=True,
description='Dump point pressure attribute (already skipped if at default value)') description='Dump point pressure attribute (already skipped if at default value)')
@@ -537,7 +534,6 @@ class GPCLIP_OT_copy_multi_strokes(bpy.types.Operator):
layout=self.layout layout=self.layout
layout.use_property_split = True layout.use_property_split = True
col = layout.column() col = layout.column()
col.prop(self, 'bake_moves')
col.label(text='Keep following point attributes:') col.label(text='Keep following point attributes:')
col.prop(self, 'pressure') col.prop(self, 'pressure')
col.prop(self, 'strength') col.prop(self, 'strength')
@@ -548,6 +544,7 @@ class GPCLIP_OT_copy_multi_strokes(bpy.types.Operator):
return return
def execute(self, context): def execute(self, context):
bake_moves = True
skip_empty_frame = False skip_empty_frame = False
org_frame = context.scene.frame_current org_frame = context.scene.frame_current
@@ -562,14 +559,14 @@ class GPCLIP_OT_copy_multi_strokes(bpy.types.Operator):
self.report({'ERROR'}, 'No layers selected in GP dopesheet (needs to be visible and selected to be copied)\nHint: Changing active layer reset selection to active only') self.report({'ERROR'}, 'No layers selected in GP dopesheet (needs to be visible and selected to be copied)\nHint: Changing active layer reset selection to active only')
return {"CANCELLED"} return {"CANCELLED"}
if not self.bake_moves: # copy only drawed frames as is. if not bake_moves: # copy only drawed frames as is.
for l in layerpool: for l in layerpool:
if not l.frames: if not l.frames:
continue# skip empty layers continue# skip empty layers
frame_dic = {} frame_dic = {}
for f in l.frames: for f in l.frames:
if skip_empty_frame and not len(f.strokes): if skip_empty_frame and not len(f.drawing.strokes):
continue continue
context.scene.frame_set(f.frame_number) # use matrix of this frame context.scene.frame_set(f.frame_number) # use matrix of this frame
strokelist = copy_all_strokes_in_frame(frame=f, layers=l, obj=obj, strokelist = copy_all_strokes_in_frame(frame=f, layers=l, obj=obj,
@@ -578,11 +575,11 @@ class GPCLIP_OT_copy_multi_strokes(bpy.types.Operator):
frame_dic[f.frame_number] = strokelist frame_dic[f.frame_number] = strokelist
layerdic[l.info] = frame_dic layerdic[l.name] = frame_dic
else: # bake position: copy frame where object as moved even if frame is unchanged else: # bake position: copy frame where object as moved even if frame is unchanged
for l in layerpool: for l in layerpool:
print('dump layer:', l.info) print('dump layer:', l.name)
if not l.frames: if not l.frames:
continue# skip empty layers continue# skip empty layers
@@ -606,7 +603,7 @@ class GPCLIP_OT_copy_multi_strokes(bpy.types.Operator):
break break
## skip empty frame if specified ## skip empty frame if specified
if skip_empty_frame and not len(f.strokes): if skip_empty_frame and not len(f.drawing.strokes):
continue continue
strokelist = copy_all_strokes_in_frame(frame=f, layers=l, obj=obj, strokelist = copy_all_strokes_in_frame(frame=f, layers=l, obj=obj,
@@ -616,7 +613,7 @@ class GPCLIP_OT_copy_multi_strokes(bpy.types.Operator):
frame_dic[i] = strokelist frame_dic[i] = strokelist
prevmat = curmat prevmat = curmat
layerdic[l.info] = frame_dic layerdic[l.name] = frame_dic
## All to clipboard manager ## All to clipboard manager
bpy.context.window_manager.clipboard = json.dumps(layerdic) bpy.context.window_manager.clipboard = json.dumps(layerdic)
@@ -636,7 +633,7 @@ class GPCLIP_OT_paste_multi_strokes(bpy.types.Operator):
#copy = bpy.props.BoolProperty(default=True) #copy = bpy.props.BoolProperty(default=True)
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
org_frame = context.scene.frame_current org_frame = context.scene.frame_current
+14 -58
View File
@@ -3,7 +3,6 @@ import bpy
import mathutils import mathutils
from bpy_extras import view3d_utils from bpy_extras import view3d_utils
from .utils import get_gp_draw_plane, region_to_location, get_view_origin_position from .utils import get_gp_draw_plane, region_to_location, get_view_origin_position
from bpy.app.handlers import persistent
## override all sursor snap shortcut with this in keymap ## override all sursor snap shortcut with this in keymap
class GPTB_OT_cusor_snap(bpy.types.Operator): class GPTB_OT_cusor_snap(bpy.types.Operator):
@@ -14,7 +13,7 @@ class GPTB_OT_cusor_snap(bpy.types.Operator):
# @classmethod # @classmethod
# def poll(cls, context): # def poll(cls, context):
# return context.object and context.object.type == 'GPENCIL' # return context.object and context.object.type == 'GREASEPENCIL'
def invoke(self, context, event): def invoke(self, context, event):
#print('-!SNAP!-') #print('-!SNAP!-')
@@ -24,7 +23,7 @@ class GPTB_OT_cusor_snap(bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
def execute(self, context): def execute(self, context):
if not context.object or context.object.type != 'GPENCIL': if not context.object or context.object.type != 'GREASEPENCIL':
self.report({'INFO'}, 'Not GP, Cursor surface project') self.report({'INFO'}, 'Not GP, Cursor surface project')
bpy.ops.view3d.cursor3d('INVOKE_DEFAULT', use_depth=True, orientation='NONE')#'NONE', 'VIEW', 'XFORM', 'GEOM' bpy.ops.view3d.cursor3d('INVOKE_DEFAULT', use_depth=True, orientation='NONE')#'NONE', 'VIEW', 'XFORM', 'GEOM'
return {"FINISHED"} return {"FINISHED"}
@@ -111,20 +110,15 @@ prev_matrix = None
# @call_once(bpy.app.handlers.frame_change_post) # @call_once(bpy.app.handlers.frame_change_post)
## used in properties file to register in boolprop update def cursor_follow_update(self,context):
def cursor_follow_update(self, context):
'''append or remove cursor_follow handler according a boolean''' '''append or remove cursor_follow handler according a boolean'''
ob = bpy.context.object
if bpy.context.scene.gptoolprops.cursor_follow_target:
## override with target object is specified
ob = bpy.context.scene.gptoolprops.cursor_follow_target
global prev_matrix global prev_matrix
# imported in properties to register in boolprop update # imported in properties to register in boolprop update
if self.cursor_follow:#True if self.cursor_follow:#True
if ob:
# out of below condition to be called when setting target as well
prev_matrix = ob.matrix_world.copy()
if not cursor_follow.__name__ in [hand.__name__ for hand in bpy.app.handlers.frame_change_post]: if not cursor_follow.__name__ in [hand.__name__ for hand in bpy.app.handlers.frame_change_post]:
if context.object:
prev_matrix = context.object.matrix_world
bpy.app.handlers.frame_change_post.append(cursor_follow) bpy.app.handlers.frame_change_post.append(cursor_follow)
else:#False else:#False
@@ -135,13 +129,11 @@ def cursor_follow_update(self, context):
def cursor_follow(scene): def cursor_follow(scene):
'''Handler to make the cursor follow active object matrix changes on frame change''' '''Handler to make the cursor follow active object matrix changes on frame change'''
ob = bpy.context.object ## TODO update global prev_matrix to equal current_matrix on selection change (need another handler)...
if bpy.context.scene.gptoolprops.cursor_follow_target: if not bpy.context.object:
## override with target object is specified
ob = bpy.context.scene.gptoolprops.cursor_follow_target
if not ob:
return return
global prev_matrix global prev_matrix
ob = bpy.context.object
current_matrix = ob.matrix_world current_matrix = ob.matrix_world
if not prev_matrix: if not prev_matrix:
prev_matrix = current_matrix.copy() prev_matrix = current_matrix.copy()
@@ -155,6 +147,8 @@ def cursor_follow(scene):
## translation only ## translation only
# scene.cursor.location += (current_matrix - prev_matrix).to_translation() # scene.cursor.location += (current_matrix - prev_matrix).to_translation()
# print('offset:', (current_matrix - prev_matrix).to_translation())
## full ## full
scene.cursor.location = current_matrix @ (prev_matrix.inverted() @ scene.cursor.location) scene.cursor.location = current_matrix @ (prev_matrix.inverted() @ scene.cursor.location)
@@ -162,38 +156,6 @@ def cursor_follow(scene):
prev_matrix = current_matrix.copy() prev_matrix = current_matrix.copy()
prev_active_obj = None
## Add check for object selection change
def selection_changed():
"""Callback function for selection changes"""
if not bpy.context.scene.gptoolprops.cursor_follow:
return
if bpy.context.scene.gptoolprops.cursor_follow_target:
# we are following a target, nothing to update on selection change
return
global prev_matrix, prev_active_obj
if prev_active_obj != bpy.context.object:
## Set stored matrix to active object
prev_matrix = bpy.context.object.matrix_world.copy()
prev_active_obj = bpy.context.object
## Note: Same owner as layer manager (will be removed as well)
def subscribe_object_change():
subscribe_to = (bpy.types.LayerObjects, 'active')
bpy.msgbus.subscribe_rna(
key=subscribe_to,
# owner of msgbus subcribe (for clearing later)
owner=bpy.types.GreasePencil, # <-- attach to ID during it's lifetime.
args=(),
notify=selection_changed,
options={'PERSISTENT'},
)
@persistent
def subscribe_object_change_handler(dummy):
subscribe_object_change()
classes = ( classes = (
GPTB_OT_cusor_snap, GPTB_OT_cusor_snap,
) )
@@ -201,18 +163,14 @@ GPTB_OT_cusor_snap,
def register(): def register():
for cls in classes: for cls in classes:
bpy.utils.register_class(cls) bpy.utils.register_class(cls)
# swap_keymap_by_id('view3d.cursor3d','view3d.cursor_snap')#auto swap to custom GP snap wrap # swap_keymap_by_id('view3d.cursor3d','view3d.cursor_snap')#auto swap to custom GP snap wrap
## Follow cursor matrix update on object change # bpy.app.handlers.frame_change_post.append(cursor_follow)
bpy.app.handlers.load_post.append(subscribe_object_change_handler) # select_change
## Directly set msgbus to work at first addon activation # select_change
bpy.app.timers.register(subscribe_object_change, first_interval=1) # select_change
## No need to frame_change_post.append(cursor_follow). Added by property update, when activating 'cursor follow'
def unregister(): def unregister():
bpy.app.handlers.load_post.remove(subscribe_object_change_handler) # select_change # bpy.app.handlers.frame_change_post.remove(cursor_follow)
# swap_keymap_by_id('view3d.cursor_snap','view3d.cursor3d')#Restore normal snap # swap_keymap_by_id('view3d.cursor_snap','view3d.cursor3d')#Restore normal snap
@@ -222,5 +180,3 @@ def unregister():
# force remove handler if it's there at unregister # force remove handler if it's there at unregister
if cursor_follow.__name__ in [hand.__name__ for hand in bpy.app.handlers.frame_change_post]: if cursor_follow.__name__ in [hand.__name__ for hand in bpy.app.handlers.frame_change_post]:
bpy.app.handlers.frame_change_post.remove(cursor_follow) bpy.app.handlers.frame_change_post.remove(cursor_follow)
bpy.msgbus.clear_by_owner(bpy.types.GreasePencil)
+19 -19
View File
@@ -231,7 +231,7 @@ class GPTB_OT_eraser(Operator):
hld_stroke.points.add(count=1) hld_stroke.points.add(count=1)
p = hld_stroke.points[-1] p = hld_stroke.points[-1]
p.co = mat_inv @ mouse_3d p.position = mat_inv @ mouse_3d
p.pressure = search_radius * 2000 p.pressure = search_radius * 2000
#context.scene.cursor.location = mouse_3d #context.scene.cursor.location = mouse_3d
@@ -252,14 +252,14 @@ class GPTB_OT_eraser(Operator):
#print(self.cuts_data) #print(self.cuts_data)
# for f in self.gp_frames: # for f in self.gp_frames:
# for s in [s for s in f.strokes if s.material_index==self.hld_index]: # for s in [s for s in f.drawing.strokes if s.material_index==self.hld_index]:
# f.strokes.remove(s) # f.drawing.strokes.remove(s)
#gp.data.materials.pop(index=self.hld_index) #gp.data.materials.pop(index=self.hld_index)
#bpy.data.materials.remove(self.hld_mat) #bpy.data.materials.remove(self.hld_mat)
bpy.ops.object.mode_set(mode='EDIT_GPENCIL') bpy.ops.object.mode_set(mode='EDIT')
context.scene.tool_settings.gpencil_selectmode_edit = 'POINT' context.scene.tool_settings.gpencil_selectmode_edit = 'POINT'
#context.scene.tool_settings.gpencil_selectmode_edit = 'POINT' #context.scene.tool_settings.gpencil_selectmode_edit = 'POINT'
@@ -281,7 +281,7 @@ class GPTB_OT_eraser(Operator):
bpy.ops.gpencil.select_all(action='DESELECT') bpy.ops.gpencil.select_all(action='DESELECT')
bpy.ops.gpencil.select_circle(x=x, y=y, radius=radius, wait_for_input=False) bpy.ops.gpencil.select_circle(x=x, y=y, radius=radius, wait_for_input=False)
strokes = [s for f in self.gp_frames for s in f.strokes] strokes = [s for f in self.gp_frames for s in f.drawing.strokes]
#print('select_circle', time()-t1) #print('select_circle', time()-t1)
t2 = time() t2 = time()
@@ -309,18 +309,18 @@ class GPTB_OT_eraser(Operator):
bpy.ops.gpencil.stroke_subdivide(number_cuts=number_cuts, only_selected=True) bpy.ops.gpencil.stroke_subdivide(number_cuts=number_cuts, only_selected=True)
new_p1 = stroke.points[p1_index+1] new_p1 = stroke.points[p1_index+1]
new_p1.co = mat_inv@intersects[0] new_p1.position = mat_inv@intersects[0]
new_points += [(stroke, p1_index+1)] new_points += [(stroke, p1_index+1)]
#print('number_cuts', number_cuts) #print('number_cuts', number_cuts)
if number_cuts == 2: if number_cuts == 2:
new_p2 = stroke.points[p1_index+2] new_p2 = stroke.points[p1_index+2]
new_p2.co = mat_inv@( (intersects[0] + intersects[1])/2 ) new_p2.position = mat_inv@( (intersects[0] + intersects[1])/2 )
#new_points += [new_p2] #new_points += [new_p2]
new_p3 = stroke.points[p1_index+3] new_p3 = stroke.points[p1_index+3]
new_p3.co = mat_inv@intersects[1] new_p3.position = mat_inv@intersects[1]
new_points += [(stroke, p1_index+3)] new_points += [(stroke, p1_index+3)]
#print('subdivide', time() - t3) #print('subdivide', time() - t3)
@@ -329,7 +329,7 @@ class GPTB_OT_eraser(Operator):
bpy.ops.gpencil.select_circle(x=x, y=y, radius=radius, wait_for_input=False) bpy.ops.gpencil.select_circle(x=x, y=y, radius=radius, wait_for_input=False)
''' '''
selected_strokes = [s for f in self.gp_frames for s in f.strokes if s.select] selected_strokes = [s for f in self.gp_frames for s in f.drawing.strokes if s.select]
tip_points = [p for s in selected_strokes for i, p in enumerate(s.points) if p.select and (i==0 or i == len(s.points)-1)] tip_points = [p for s in selected_strokes for i, p in enumerate(s.points) if p.select and (i==0 or i == len(s.points)-1)]
bpy.ops.gpencil.select_less() bpy.ops.gpencil.select_less()
@@ -341,7 +341,7 @@ class GPTB_OT_eraser(Operator):
''' '''
t4 = time() t4 = time()
selected_strokes = [s for f in self.gp_frames for s in f.strokes if s.select] selected_strokes = [s for f in self.gp_frames for s in f.drawing.strokes if s.select]
if selected_strokes: if selected_strokes:
bpy.ops.gpencil.delete(type='POINTS') bpy.ops.gpencil.delete(type='POINTS')
@@ -358,9 +358,9 @@ class GPTB_OT_eraser(Operator):
#bpy.ops.object.mode_set(mode='OBJECT') #bpy.ops.object.mode_set(mode='OBJECT')
context.scene.tool_settings.gpencil_selectmode_edit = self.gpencil_selectmode_edit context.scene.tool_settings.gpencil_selectmode_edit = self.gpencil_selectmode_edit
bpy.ops.object.mode_set(mode='PAINT_GPENCIL') bpy.ops.object.mode_set(mode='PAINT_GREASE_PENCIL')
#selected_strokes = [s for s in self.gp_frame.strokes if s.select] #selected_strokes = [s for s in self.gp_frame.drawing.strokes if s.select]
#bpy.ops.object.mode_set(mode='PAINT_GPENCIL') #bpy.ops.object.mode_set(mode='PAINT_GREASE_PENCIL')
def modal(self, context, event): def modal(self, context, event):
self.mouse = Vector((event.mouse_region_x, event.mouse_region_y)) self.mouse = Vector((event.mouse_region_x, event.mouse_region_y))
@@ -441,22 +441,22 @@ class GPTB_OT_eraser(Operator):
t0 = time() t0 = time()
gp_mats = gp.data.materials gp_mats = gp.data.materials
gp_layers = [l for l in gp.data.layers if not l.lock or l.hide] gp_layers = [l for l in gp.data.layers if not l.lock or l.hide]
self.gp_frames = [l.active_frame for l in gp_layers] self.gp_frames = [l.current_frame() for l in gp_layers]
''' '''
points_data = [(s, f, gp_mats[s.material_index]) for f in gp_frames for s in f.strokes] points_data = [(s, f, gp_mats[s.material_index]) for f in gp_frames for s in f.drawing.strokes]
points_data = [(s, f, m) for s, f, m in points_data if not m.grease_pencil.hide or m.grease_pencil.lock] points_data = [(s, f, m) for s, f, m in points_data if not m.grease_pencil.hide or m.grease_pencil.lock]
print('get_gp_points', time()-t0) print('get_gp_points', time()-t0)
t0 = time() t0 = time()
#points_data = [(s, f, m, p, get_screen_co(p.co, matrix)) for s, f, m in points_data for p in reversed(s.points)] #points_data = [(s, f, m, p, get_screen_co(p.position, matrix)) for s, f, m in points_data for p in reversed(s.points)]
points_data = [(s, f, m, p, org + ((matrix @ p.co)-org).normalized()*1) for s, f, m in points_data for p in reversed(s.points)] points_data = [(s, f, m, p, org + ((matrix @ p.position)-org).normalized()*1) for s, f, m in points_data for p in reversed(s.points)]
print('points_to_2d', time()-t0) print('points_to_2d', time()-t0)
#print(points_data) #print(points_data)
self.points_data = [(s, f, m, p, co) for s, f, m, p, co in points_data if co is not None] self.points_data = [(s, f, m, p, co) for s, f, m, p, co in points_data if co is not None]
#for s, f, m, p, co in self.points_data: #for s, f, m, p, co in self.points_data:
# p.co = co # p.position = co
t0 = time() t0 = time()
@@ -481,7 +481,7 @@ class GPTB_OT_eraser(Operator):
self.hld_strokes = [] self.hld_strokes = []
for f in self.gp_frames: for f in self.gp_frames:
hld_stroke = f.strokes.new() hld_stroke = f.drawing.strokes.new()
hld_stroke.start_cap_mode = 'ROUND' hld_stroke.start_cap_mode = 'ROUND'
hld_stroke.end_cap_mode = 'ROUND' hld_stroke.end_cap_mode = 'ROUND'
hld_stroke.material_index = self.hld_index hld_stroke.material_index = self.hld_index
+88 -295
View File
@@ -4,11 +4,6 @@ from pathlib import Path
import numpy as np import numpy as np
from . import utils from . import utils
from bpy.props import (BoolProperty,
PointerProperty,
CollectionProperty,
StringProperty)
def remove_stroke_exact_duplications(apply=True): def remove_stroke_exact_duplications(apply=True):
'''Remove accidental stroke duplication (points exactly in the same place) '''Remove accidental stroke duplication (points exactly in the same place)
:apply: Remove the duplication instead of just listing dupes :apply: Remove the duplication instead of just listing dupes
@@ -21,15 +16,15 @@ def remove_stroke_exact_duplications(apply=True):
for l in gp.layers: for l in gp.layers:
for f in l.frames: for f in l.frames:
stroke_list = [] stroke_list = []
for s in reversed(f.strokes): for s in reversed(f.drawing.strokes):
point_list = [p.co for p in s.points] point_list = [p.position for p in s.points]
if point_list in stroke_list: if point_list in stroke_list:
ct += 1 ct += 1
if apply: if apply:
# Remove redundancy # Remove redundancy
f.strokes.remove(s) f.drawing.strokes.remove(s)
else: else:
stroke_list.append(point_list) stroke_list.append(point_list)
return ct return ct
@@ -58,10 +53,6 @@ class GPTB_OT_file_checker(bpy.types.Operator):
# Disable use light on all object # Disable use light on all object
# Remove redundant strokes in frames # Remove redundant strokes in frames
apply_fixes : bpy.props.BoolProperty(name="Apply Fixes", default=False,
description="Apply possible fixes instead of just listing (pop the list again in fix mode)",
options={'SKIP_SAVE'})
def invoke(self, context, event): def invoke(self, context, event):
# need some self-control (I had to...) # need some self-control (I had to...)
self.ctrl = event.ctrl self.ctrl = event.ctrl
@@ -72,14 +63,10 @@ class GPTB_OT_file_checker(bpy.types.Operator):
fix = prefs.fixprops fix = prefs.fixprops
problems = [] problems = []
## Old method : Apply fixes based on pref (inverted by ctrl key) apply = not fix.check_only
# apply = not fix.check_only
# # If Ctrl is pressed, invert behavior (invert boolean)
# apply ^= self.ctrl
apply = self.apply_fixes # If Ctrl is pressed, invert behavior (invert boolean)
if self.ctrl: apply ^= self.ctrl
apply = True
## Lock main cam: ## Lock main cam:
if fix.lock_main_cam: if fix.lock_main_cam:
@@ -133,7 +120,7 @@ class GPTB_OT_file_checker(bpy.types.Operator):
setattr(area.spaces[0], 'show_locked_time', True) setattr(area.spaces[0], 'show_locked_time', True)
## set cursor type ## set cursor type
if context.mode in ("EDIT_GPENCIL", "SCULPT_GPENCIL"): if context.mode in ("EDIT_GREASE_PENCIL", "SCULPT_GREASE_PENCIL"):
tool = fix.select_active_tool tool = fix.select_active_tool
if tool != 'none': if tool != 'none':
if bpy.context.workspace.tools.from_space_view3d_mode(bpy.context.mode, create=False).idname != tool: if bpy.context.workspace.tools.from_space_view3d_mode(bpy.context.mode, create=False).idname != tool:
@@ -158,7 +145,7 @@ class GPTB_OT_file_checker(bpy.types.Operator):
## GP Use light disable ## GP Use light disable
if fix.set_gp_use_lights_off: if fix.set_gp_use_lights_off:
gp_with_lights = [o for o in context.scene.objects if o.type == 'GPENCIL' and o.use_grease_pencil_lights] gp_with_lights = [o for o in context.scene.objects if o.type == 'GREASEPENCIL' and o.use_grease_pencil_lights]
if gp_with_lights: if gp_with_lights:
problems.append(f'Disable "Use Lights" on {len(gp_with_lights)} Gpencil objects') problems.append(f'Disable "Use Lights" on {len(gp_with_lights)} Gpencil objects')
if apply: if apply:
@@ -182,46 +169,37 @@ class GPTB_OT_file_checker(bpy.types.Operator):
if fix.list_obj_vis_conflict: if fix.list_obj_vis_conflict:
viz_ct = 0 viz_ct = 0
for o in context.scene.objects: for o in context.scene.objects:
if not (o.hide_get() == o.hide_viewport == o.hide_render): if o.hide_viewport != o.hide_render:
hv = 'No' if o.hide_get() else 'Yes'
vp = 'No' if o.hide_viewport else 'Yes' vp = 'No' if o.hide_viewport else 'Yes'
rd = 'No' if o.hide_render else 'Yes' rd = 'No' if o.hide_render else 'Yes'
viz_ct += 1 viz_ct += 1
print(f'{o.name} : viewlayer {hv} - viewport {vp} - render {rd}') print(f'{o.name} : viewport {vp} != render {rd}')
if viz_ct: if viz_ct:
problems.append(['gp.list_object_visibility_conflicts', f'{viz_ct} objects visibility conflicts (details in console)', 'OBJECT_DATAMODE']) problems.append(['gp.list_object_visibility', f'{viz_ct} objects visibility conflicts (details in console)', 'OBJECT_DATAMODE'])
## GP modifiers visibility conflict ## GP modifiers visibility conflict
if fix.list_gp_mod_vis_conflict: if fix.list_gp_mod_vis_conflict:
mod_viz_ct = 0 mod_viz_ct = 0
for o in context.scene.objects: for o in context.scene.objects:
if o.type == 'GPENCIL': for m in o.modifiers:
for m in o.grease_pencil_modifiers: if m.show_viewport != m.show_render:
if m.show_viewport != m.show_render: vp = 'Yes' if m.show_viewport else 'No'
vp = 'Yes' if m.show_viewport else 'No' rd = 'Yes' if m.show_render else 'No'
rd = 'Yes' if m.show_render else 'No' mod_viz_ct += 1
mod_viz_ct += 1 print(f'{o.name} - modifier {m.name}: viewport {vp} != render {rd}')
print(f'{o.name} - GP modifier {m.name}: viewport {vp} != render {rd}')
else:
for m in o.modifiers:
if m.show_viewport != m.show_render:
vp = 'Yes' if m.show_viewport else 'No'
rd = 'Yes' if m.show_render else 'No'
mod_viz_ct += 1
print(f'{o.name} - modifier {m.name}: viewport {vp} != render {rd}')
if mod_viz_ct: if mod_viz_ct:
problems.append(['gp.list_modifier_visibility', f'{mod_viz_ct} modifiers visibility conflicts (details in console)', 'MODIFIER_DATA']) problems.append(['gp.list_modifier_visibility', f'{mod_viz_ct} modifiers visibility conflicts (details in console)', 'MODIFIER_DATA'])
## check if GP modifier have broken layer targets ## check if GP modifier have broken layer targets
if fix.list_broken_mod_targets: if fix.list_broken_mod_targets:
for o in [o for o in bpy.context.scene.objects if o.type == 'GPENCIL']: for o in [o for o in bpy.context.scene.objects if o.type == 'GREASEPENCIL']:
lay_name_list = [l.info for l in o.data.layers] lay_name_list = [l.name for l in o.data.layers]
for m in o.grease_pencil_modifiers: for m in o.modifiers:
if not hasattr(m, 'layer'): if not hasattr(m, 'layer_filter'):
continue continue
if m.layer != '' and not m.layer in lay_name_list: if m.layer_filter != '' and not m.layer_filter in lay_name_list:
mess = f'Broken modifier layer target: {o.name} > {m.name} > {m.layer}' mess = f'Broken modifier layer target: {o.name} > {m.name} > {m.layer_filter}'
print(mess) print(mess)
problems.append(mess) problems.append(mess)
@@ -291,7 +269,7 @@ class GPTB_OT_file_checker(bpy.types.Operator):
# problems.append(f"{fix_kf_type} GP onion skin filter to 'All type'") # problems.append(f"{fix_kf_type} GP onion skin filter to 'All type'")
# for ob in context.scene.objects:#from object # for ob in context.scene.objects:#from object
# if ob.type == 'GPENCIL': # if ob.type == 'GREASEPENCIL':
# ob.data.onion_keyframe_type = 'ALL' # ob.data.onion_keyframe_type = 'ALL'
#### --- print fix/problems report #### --- print fix/problems report
@@ -303,12 +281,8 @@ class GPTB_OT_file_checker(bpy.types.Operator):
else: else:
print(p[0]) print(p[0])
if not self.apply_fixes:
## button to call the operator again with apply_fixes set to True
problems.append(['OPERATOR', 'gp.file_checker', 'Apply Fixes', 'FORWARD', {'apply_fixes': True}])
# Show in viewport # Show in viewport
title = "Changed Settings" if apply else "Checked Settings (nothing changed)" title = "Changed Settings" if apply else "Checked Settings (dry run, nothing changed)"
utils.show_message_box(problems, _title = title, _icon = 'INFO') utils.show_message_box(problems, _title = title, _icon = 'INFO')
else: else:
self.report({'INFO'}, 'All good') self.report({'INFO'}, 'All good')
@@ -507,9 +481,46 @@ class GPTB_OT_links_checker(bpy.types.Operator):
self.proj = os.environ.get('PROJECT_ROOT') self.proj = os.environ.get('PROJECT_ROOT')
return context.window_manager.invoke_props_dialog(self, width=popup_width) return context.window_manager.invoke_props_dialog(self, width=popup_width)
class GPTB_OT_list_viewport_render_visibility(bpy.types.Operator):
bl_idname = "gp.list_viewport_render_visibility" """ OLD links checker with show_message_box
bl_label = "List Viewport And Render Visibility Conflicts" class GPTB_OT_links_checker(bpy.types.Operator):
bl_idname = "gp.links_checker"
bl_label = "Links check"
bl_description = "Check states of file direct links"
bl_options = {"REGISTER"}
def execute(self, context):
all_lnks = []
has_broken_link = False
## check for broken links
for current, lib in zip(bpy.utils.blend_paths(local=True), bpy.utils.blend_paths(absolute=True, local=True)):
lfp = Path(lib)
realib = Path(current)
if not lfp.exists():
has_broken_link = True
all_lnks.append( (f"Broken link: {realib.as_posix()}", 'LIBRARY_DATA_BROKEN') )#lfp.as_posix()
else:
if realib.as_posix().startswith('//'):
all_lnks.append( (f"Link: {realib.as_posix()}", 'LINKED') )#lfp.as_posix()
else:
all_lnks.append( (f"Link: {realib.as_posix()}", 'LIBRARY_DATA_INDIRECT') )#lfp.as_posix()
all_lnks.sort(key=lambda x: x[1], reverse=True)
if all_lnks:
print('===File check===')
for p in all_lnks:
if isinstance(p, str):
print(p)
else:
print(p[0])
# Show in viewport
utils.show_message_box(all_lnks, _title = "Links", _icon = 'INFO')
return {"FINISHED"} """
class GPTB_OT_list_object_visibility(bpy.types.Operator):
bl_idname = "gp.list_object_visibility"
bl_label = "List Object Visibility Conflicts"
bl_description = "List objects visibility conflicts, when viewport and render have different values" bl_description = "List objects visibility conflicts, when viewport and render have different values"
bl_options = {"REGISTER"} bl_options = {"REGISTER"}
@@ -528,221 +539,20 @@ class GPTB_OT_list_viewport_render_visibility(bpy.types.Operator):
def execute(self, context): def execute(self, context):
return {'FINISHED'} return {'FINISHED'}
## basic listing as message box # all in invoke now
### -- Sync visibility ops (Could be fused in one ops, but having 3 different operators allow to call from search menu) # li = []
class GPTB_OT_sync_visibility_from_viewlayer(bpy.types.Operator): # viz_ct = 0
bl_idname = "gp.sync_visibility_from_viewlayer" # for o in context.scene.objects:
bl_label = "Sync Visibility From Viewlayer" # if o.hide_viewport != o.hide_render:
bl_description = "Set viewport and render visibility to match viewlayer visibility" # vp = 'No' if o.hide_viewport else 'Yes'
bl_options = {"REGISTER", "UNDO"} # rd = 'No' if o.hide_render else 'Yes'
# viz_ct += 1
def execute(self, context): # li.append(f'{o.name} : viewport {vp} != render {rd}')
for obj in context.scene.objects: # if li:
is_hidden = obj.hide_get() # Get viewlayer visibility # utils.show_message_box(_message=li, _title=f'{viz_ct} visibility conflicts found')
obj.hide_viewport = is_hidden # else:
obj.hide_render = is_hidden # self.report({'INFO'}, f"No Object visibility conflict on current scene")
return {'FINISHED'} # return {'FINISHED'}
class GPTB_OT_sync_visibility_from_viewport(bpy.types.Operator):
bl_idname = "gp.sync_visibility_from_viewport"
bl_label = "Sync Visibility From Viewport"
bl_description = "Set viewlayer and render visibility to match viewport visibility"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
for obj in context.scene.objects:
is_hidden = obj.hide_viewport
obj.hide_set(is_hidden)
obj.hide_render = is_hidden
return {'FINISHED'}
class GPTB_OT_sync_visibility_from_render(bpy.types.Operator):
bl_idname = "gp.sync_visibility_from_render"
bl_label = "Sync Visibility From Render"
bl_description = "Set viewlayer and viewport visibility to match render visibility"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
for obj in context.scene.objects:
is_hidden = obj.hide_render
obj.hide_set(is_hidden)
obj.hide_viewport = is_hidden
return {'FINISHED'}
class GPTB_OT_sync_visibible_to_render(bpy.types.Operator):
bl_idname = "gp.sync_visibible_to_render"
bl_label = "Sync Overall Viewport Visibility To Render"
bl_description = "Set render visibility from"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
for obj in context.scene.objects:
## visible_get is the current visibility status combination of hide_viewport and viewlayer hide (eye)
obj.hide_render = not obj.visible_get()
return {'FINISHED'}
class GPTB_PG_object_visibility(bpy.types.PropertyGroup):
"""Property group to handle object visibility"""
is_hidden: BoolProperty(
name="Hide in Viewport",
description="Toggle object visibility in viewport",
get=lambda self: self.get("is_hidden", False),
set=lambda self, value: self.set_visibility(value)
)
object_name: StringProperty(name="Object Name")
def set_visibility(self, value):
"""Set the visibility using hide_set()"""
obj = bpy.context.view_layer.objects.get(self.object_name)
if obj:
obj.hide_set(value)
self["is_hidden"] = value
class GPTB_OT_list_object_visibility_conflicts(bpy.types.Operator):
bl_idname = "gp.list_object_visibility_conflicts"
bl_label = "List Object Visibility Conflicts"
bl_description = "List objects visibility conflicts, when viewport and render have different values"
bl_options = {"REGISTER"}
visibility_items: CollectionProperty(type=GPTB_PG_object_visibility) # type: ignore[valid-type]
## options:
# check_viewlayer : BoolProperty(name="Check Viewlayer", default=False, description="Compare viewlayer (eye) visibility")
# check_viewport : BoolProperty(name="Check Viewport", default=False, description="Compare Viewport (screen icon) visibility")
# check_render : BoolProperty(name="Check Viewport", default=False, description="Compare Render visibility")
def invoke(self, context, event):
# Clear and rebuild both collections
self.visibility_items.clear()
# Store objects with conflicts
objects_with_conflicts = [o for o in context.scene.objects if not (o.hide_get() == o.hide_viewport == o.hide_render)]
# Create visibility items
for obj in objects_with_conflicts:
item = self.visibility_items.add()
item.object_name = obj.name
item["is_hidden"] = obj.hide_get()
return context.window_manager.invoke_props_dialog(self, width=250)
def draw(self, context):
layout = self.layout
# row.prop(self, "check_viewlayer")
# row.prop(self, "check_viewport")
# row.prop(self, "check_render")
## If filtered by prop, displayed list will resize while applying changes ! (not good)
# Add sync buttons at the top
row = layout.row(align=False)
row.label(text="Sync All Visibility From:")
row.operator("gp.sync_visibility_from_viewlayer", text="", icon='HIDE_OFF')
row.operator("gp.sync_visibility_from_viewport", text="", icon='RESTRICT_VIEW_OFF')
row.operator("gp.sync_visibility_from_render", text="", icon='RESTRICT_RENDER_OFF')
layout.separator()
col = layout.column()
# We can safely iterate over visibility_items since objects are stored in same order
for vis_item in self.visibility_items:
obj = context.view_layer.objects.get(vis_item.object_name)
if not obj:
continue
row = col.row(align=False)
row.label(text=obj.name)
## Viewlayer visibility "as prop" to allow slide toggle
# hide_icon='HIDE_ON' if vis_item.is_hidden else 'HIDE_OFF'
hide_icon='HIDE_ON' if obj.hide_get() else 'HIDE_OFF'
row.prop(vis_item, "is_hidden", text="", icon=hide_icon, emboss=False)
# Direct object properties
row.prop(obj, 'hide_viewport', text='', emboss=False)
row.prop(obj, 'hide_render', text='', emboss=False)
def execute(self, context):
return {'FINISHED'}
def get_collection_children_recursive(col, cols=None) -> list:
'''return a list of all the child collections
and their subcollections in the passed collection'''
cols = cols or []
for sub in col.children:
if sub not in cols:
cols.append(sub)
if len(sub.children):
cols = get_collection_children_recursive(sub, cols)
return cols
class GPTB_OT_list_collection_visibility_conflicts(bpy.types.Operator):
bl_idname = "gp.list_collection_visibility_conflicts"
bl_label = "List Collection Visibility Conflicts"
bl_description = "List collection visibility conflicts, when viewport and render have different values"
bl_options = {"REGISTER"}
# visibility_items: CollectionProperty(type=GPTB_PG_collection_visibility)
show_filter : bpy.props.EnumProperty(
name="View Filter",
description="Filter collections based on their exclusion status",
items=(
('ALL', "All", "Show all collections", 0),
('NOT_EXCLUDED', "Not Excluded", "Show collections that are not excluded", 1),
('EXCLUDED', "Excluded", "Show collections that are excluded", 2)
),
default='NOT_EXCLUDED')
def invoke(self, context, event):
## get all viewlayer collections
vcols = get_collection_children_recursive(context.view_layer.layer_collection)
vcols = list(set(vcols)) # ensure no duplicates
## Store collection with conflicts
# layer_collection.is_visible against render visibility ?
## Do not list currently excluded collections
self.conflict_collections = [vc for vc in vcols if not (vc.hide_viewport == vc.collection.hide_viewport == vc.collection.hide_render)]
self.included_collection = [vc for vc in self.conflict_collections if not vc.exclude]
self.excluded_collection = [vc for vc in self.conflict_collections if vc.exclude]
return context.window_manager.invoke_props_dialog(self, width=250)
def draw(self, context):
layout = self.layout
layout.prop(self, 'show_filter', expand=True)
# Add sync buttons at the top
row = layout.row(align=False)
# TODO: Add "set all from" ops on collection (optionnal)
# row.label(text="Sync All Visibility From:")
# row.operator("gp.sync_visibility_from_viewlayer", text="", icon='HIDE_OFF')
# row.operator("gp.sync_visibility_from_viewport", text="", icon='RESTRICT_VIEW_OFF')
# row.operator("gp.sync_visibility_from_render", text="", icon='RESTRICT_RENDER_OFF')
layout.separator()
if self.show_filter == 'ALL':
vl_collections = self.conflict_collections
elif self.show_filter == 'EXCLUDED':
vl_collections = self.excluded_collection
elif self.show_filter == 'NOT_EXCLUDED':
vl_collections = self.included_collection
col = layout.column()
for vlcol in vl_collections:
row = col.row(align=False)
row.label(text=vlcol.name)
# Viewlayer collection settings
row.prop(vlcol, "exclude", text="", emboss=False)
row.prop(vlcol, "hide_viewport", text="", emboss=False)
# Direct collection properties
row.prop(vlcol.collection, 'hide_viewport', text='', emboss=False)
row.prop(vlcol.collection, 'hide_render', text='', emboss=False)
def execute(self, context):
return {'FINISHED'}
## not exposed in UI, Check is performed in Check file (can be called in popped menu) ## not exposed in UI, Check is performed in Check file (can be called in popped menu)
class GPTB_OT_list_modifier_visibility(bpy.types.Operator): class GPTB_OT_list_modifier_visibility(bpy.types.Operator):
@@ -754,24 +564,14 @@ class GPTB_OT_list_modifier_visibility(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
self.ob_list = [] self.ob_list = []
for o in context.scene.objects: for o in context.scene.objects:
if o.type == 'GPENCIL': if not len(o.modifiers):
if not len(o.grease_pencil_modifiers): continue
continue mods = []
mods = [] for m in o.modifiers:
for m in o.grease_pencil_modifiers: if m.show_viewport != m.show_render:
if m.show_viewport != m.show_render: if not mods:
if not mods: self.ob_list.append([o, mods, "OUTLINER_OB_" + o.type])
self.ob_list.append([o, mods, 'OUTLINER_OB_GREASEPENCIL']) mods.append(m)
mods.append(m)
else:
if not len(o.modifiers):
continue
mods = []
for m in o.modifiers:
if m.show_viewport != m.show_render:
if not mods:
self.ob_list.append([o, mods, "OUTLINER_OB_" + o.type])
mods.append(m)
self.ob_list.sort(key=lambda x: x[2]) # regroup by objects type (this or x[0] for object name) self.ob_list.sort(key=lambda x: x[2]) # regroup by objects type (this or x[0] for object name)
return context.window_manager.invoke_props_dialog(self, width=250) return context.window_manager.invoke_props_dialog(self, width=250)
@@ -794,14 +594,7 @@ class GPTB_OT_list_modifier_visibility(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
classes = ( classes = (
GPTB_OT_list_viewport_render_visibility, # Only viewport and render GPTB_OT_list_object_visibility,
GPTB_OT_sync_visibility_from_viewlayer,
GPTB_OT_sync_visibility_from_viewport,
GPTB_OT_sync_visibility_from_render,
GPTB_OT_sync_visibible_to_render,
GPTB_PG_object_visibility,
GPTB_OT_list_object_visibility_conflicts,
GPTB_OT_list_collection_visibility_conflicts,
GPTB_OT_list_modifier_visibility, GPTB_OT_list_modifier_visibility,
GPTB_OT_copy_string_to_clipboard, GPTB_OT_copy_string_to_clipboard,
GPTB_OT_copy_multipath_clipboard, GPTB_OT_copy_multipath_clipboard,
+17 -17
View File
@@ -19,7 +19,7 @@ def batch_flat_reproject(obj, proj_type='VIEW', all_strokes=True, restore_frame=
oframe = bpy.context.scene.frame_current oframe = bpy.context.scene.frame_current
omode = bpy.context.mode omode = bpy.context.mode
# frame_list = [ f.frame_number for l in obj.data.layers for f in l.frames if len(f.strokes)] # frame_list = [ f.frame_number for l in obj.data.layers for f in l.frames if len(f.drawing.strokes)]
# frame_list = list(set(frame_list)) # frame_list = list(set(frame_list))
# frame_list.sort() # frame_list.sort()
# for fnum in frame_list: # for fnum in frame_list:
@@ -32,15 +32,15 @@ def batch_flat_reproject(obj, proj_type='VIEW', all_strokes=True, restore_frame=
fnum = len(l.frames) fnum = len(l.frames)
zf = len(str(fnum)) zf = len(str(fnum))
for j, f in enumerate(reversed(l.frames)): # whynot... for j, f in enumerate(reversed(l.frames)): # whynot...
print(f'{obj.name} : {i+1}/{laynum} : {l.info} : {str(j+1).zfill(zf)}/{fnum}{" "*30}', end='\r') print(f'{obj.name} : {i+1}/{laynum} : {l.name} : {str(j+1).zfill(zf)}/{fnum}{" "*30}', end='\r')
scn.frame_set(f.frame_number) # more chance to update the matrix scn.frame_set(f.frame_number) # more chance to update the matrix
bpy.context.view_layer.update() # update the matrix ? bpy.context.view_layer.update() # update the matrix ?
bpy.context.scene.camera.location = bpy.context.scene.camera.location bpy.context.scene.camera.location = bpy.context.scene.camera.location
scn.frame_current = f.frame_number scn.frame_current = f.frame_number
for s in f.strokes: for s in f.drawing.strokes:
for p in s.points: for p in s.points:
p.co = obj.matrix_world.inverted() @ region_to_location(location_to_region(obj.matrix_world @ p.co), scn.cursor.location) p.position = obj.matrix_world.inverted() @ region_to_location(location_to_region(obj.matrix_world @ p.position), scn.cursor.location)
if restore_frame: if restore_frame:
bpy.context.scene.frame_current = oframe bpy.context.scene.frame_current = oframe
@@ -67,8 +67,8 @@ def batch_flat_reproject(obj):
plane_no.rotate(cam_mat) plane_no.rotate(cam_mat)
plane_co = scn.cursor.location plane_co = scn.cursor.location
for s in f.strokes: for s in f.drawing.strokes:
points_co = [obj.matrix_world @ p.co for p in s.points] points_co = [obj.matrix_world @ p.position for p in s.points]
points_co = [mat_inv @ intersect_line_plane(origin, p, plane_co, plane_no) for p in points_co] points_co = [mat_inv @ intersect_line_plane(origin, p, plane_co, plane_no) for p in points_co]
points_co = [co for vector in points_co for co in vector] points_co = [co for vector in points_co for co in vector]
@@ -76,8 +76,8 @@ def batch_flat_reproject(obj):
s.points.add(1) # update s.points.add(1) # update
s.points.pop() # update s.points.pop() # update
#for p in s.points: #for p in s.points:
# loc_2d = location_to_region(obj.matrix_world @ p.co) # loc_2d = location_to_region(obj.matrix_world @ p.position)
# p.co = obj.matrix_world.inverted() @ region_to_location(loc_2d, scn.cursor.location) # p.position = obj.matrix_world.inverted() @ region_to_location(loc_2d, scn.cursor.location)
""" """
def batch_flat_reproject(obj): def batch_flat_reproject(obj):
@@ -96,14 +96,14 @@ def batch_flat_reproject(obj):
plane_co = scn.cursor.location plane_co = scn.cursor.location
for l in obj.data.layers: for l in obj.data.layers:
f = l.active_frame f = l.current_frame()
if not f: # No active frame if not f: # No active frame
continue continue
if f.frame_number != scn.frame_current: if f.frame_number != scn.frame_current:
f = l.frames.copy(f) # duplicate content of the previous frame f = l.frames.copy(f) # duplicate content of the previous frame
for s in f.strokes: for s in f.drawing.strokes:
points_co = [obj.matrix_world @ p.co for p in s.points] points_co = [obj.matrix_world @ p.position for p in s.points]
points_co = [mat_inv @ intersect_line_plane(origin, p, plane_co, plane_no) for p in points_co] points_co = [mat_inv @ intersect_line_plane(origin, p, plane_co, plane_no) for p in points_co]
points_co = [co for vector in points_co for co in vector] points_co = [co for vector in points_co for co in vector]
@@ -119,11 +119,11 @@ class GPTB_OT_batch_flat_reproject(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
for o in context.selected_objects: for o in context.selected_objects:
if o.type != 'GPENCIL' or not o.select_get(): if o.type != 'GREASEPENCIL' or not o.select_get():
continue continue
batch_flat_reproject(o) batch_flat_reproject(o)
@@ -132,12 +132,12 @@ class GPTB_OT_batch_flat_reproject(bpy.types.Operator):
### -- MENU ENTRY -- ### -- MENU ENTRY --
def flat_reproject_clean_menu(self, context): def flat_reproject_clean_menu(self, context):
if context.mode == 'EDIT_GPENCIL': if context.mode == 'EDIT_GREASE_PENCIL':
self.layout.operator_context = 'INVOKE_REGION_WIN' # needed for popup (also works with 'INVOKE_DEFAULT') self.layout.operator_context = 'INVOKE_REGION_WIN' # needed for popup (also works with 'INVOKE_DEFAULT')
self.layout.operator('gp.batch_flat_reproject', icon='KEYTYPE_JITTER_VEC') self.layout.operator('gp.batch_flat_reproject', icon='KEYTYPE_JITTER_VEC')
def flat_reproject_context_menu(self, context): def flat_reproject_context_menu(self, context):
if context.mode == 'EDIT_GPENCIL' and context.scene.tool_settings.gpencil_selectmode_edit == 'STROKE': if context.mode == 'EDIT_GREASE_PENCIL' and context.scene.tool_settings.gpencil_selectmode_edit == 'STROKE':
self.layout.operator_context = 'INVOKE_REGION_WIN' # needed for popup self.layout.operator_context = 'INVOKE_REGION_WIN' # needed for popup
self.layout.operator('gp.batch_flat_reproject', icon='KEYTYPE_JITTER_VEC') self.layout.operator('gp.batch_flat_reproject', icon='KEYTYPE_JITTER_VEC')
@@ -149,12 +149,12 @@ def register():
for cl in classes: for cl in classes:
bpy.utils.register_class(cl) bpy.utils.register_class(cl)
# bpy.types.VIEW3D_MT_gpencil_edit_context_menu.append(flat_reproject_context_menu) # bpy.types.VIEW3D_MT_grease_pencil_edit_context_menu.append(flat_reproject_context_menu)
# bpy.types.GPENCIL_MT_cleanup.append(flat_reproject_clean_menu) # bpy.types.GPENCIL_MT_cleanup.append(flat_reproject_clean_menu)
def unregister(): def unregister():
# bpy.types.GPENCIL_MT_cleanup.remove(flat_reproject_clean_menu) # bpy.types.GPENCIL_MT_cleanup.remove(flat_reproject_clean_menu)
# bpy.types.VIEW3D_MT_gpencil_edit_context_menu.remove(flat_reproject_context_menu) # bpy.types.VIEW3D_MT_grease_pencil_edit_context_menu.remove(flat_reproject_context_menu)
for cl in reversed(classes): for cl in reversed(classes):
bpy.utils.unregister_class(cl) bpy.utils.unregister_class(cl)
+2 -2
View File
@@ -135,8 +135,8 @@ class GPTB_OT_go_to_object(bpy.types.Operator):
bpy.ops.object.mode_set(mode='POSE', toggle=False) bpy.ops.object.mode_set(mode='POSE', toggle=False)
self.report({'INFO'}, f'Back to pose mode, {obj.name}') self.report({'INFO'}, f'Back to pose mode, {obj.name}')
elif obj.type == 'GPENCIL': elif obj.type == 'GREASEPENCIL':
bpy.ops.object.mode_set(mode='PAINT_GPENCIL', toggle=False) bpy.ops.object.mode_set(mode='PAINT_GREASE_PENCIL', toggle=False)
else: else:
self.report({'INFO'}, f'Back to object mode, {obj.name}') self.report({'INFO'}, f'Back to object mode, {obj.name}')
+18 -18
View File
@@ -79,7 +79,7 @@ class GPTB_OT_rename_data_from_obj(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
if not self.rename_all: if not self.rename_all:
@@ -93,7 +93,7 @@ class GPTB_OT_rename_data_from_obj(Operator):
else: else:
oblist = [] oblist = []
for o in context.scene.objects: for o in context.scene.objects:
if o.type == 'GPENCIL': if o.type == 'GREASEPENCIL':
if o.name == o.data.name: if o.name == o.data.name:
continue continue
oblist.append(f'{o.data.name} -> {o.name}') oblist.append(f'{o.data.name} -> {o.name}')
@@ -250,7 +250,7 @@ class GPTB_OT_draw_cam(Operator):
drawcam.parent = act drawcam.parent = act
vec = Vector((0,1,0)) vec = Vector((0,1,0))
if act.type == 'GPENCIL': if act.type == 'GREASEPENCIL':
#change vector according to alignement #change vector according to alignement
vec = get_gp_alignement_vector(context) vec = get_gp_alignement_vector(context)
@@ -427,15 +427,15 @@ class GPTB_OT_toggle_mute_animation(Operator):
pool = context.scene.objects pool = context.scene.objects
for o in pool: for o in pool:
if self.mode == 'GPENCIL' and o.type != 'GPENCIL': if self.mode == 'GREASEPENCIL' and o.type != 'GREASEPENCIL':
continue continue
if self.mode == 'OBJECT' and o.type in ('GPENCIL', 'CAMERA'): if self.mode == 'OBJECT' and o.type in ('GREASEPENCIL', 'CAMERA'):
continue continue
if self.mode == 'CAMERA' and o.type != 'CAMERA': if self.mode == 'CAMERA' and o.type != 'CAMERA':
continue continue
# mute attribute animation for GP and cameras # mute attribute animation for GP and cameras
if o.type in ('GPENCIL', 'CAMERA') and o.data.animation_data: if o.type in ('GREASEPENCIL', 'CAMERA') and o.data.animation_data:
gp_act = o.data.animation_data.action gp_act = o.data.animation_data.action
if gp_act: if gp_act:
print(f'\n---{o.name} data:') print(f'\n---{o.name} data:')
@@ -473,9 +473,9 @@ class GPTB_OT_toggle_hide_gp_modifier(Operator):
else: else:
pool = context.scene.objects pool = context.scene.objects
for o in pool: for o in pool:
if o.type != 'GPENCIL': if o.type != 'GREASEPENCIL':
continue continue
for m in o.grease_pencil_modifiers: for m in o.modifier:
# skip modifier that are not visible in render # skip modifier that are not visible in render
if not m.show_render: if not m.show_render:
continue continue
@@ -506,12 +506,12 @@ class GPTB_OT_list_disabled_anims(Operator):
pool = context.scene.objects pool = context.scene.objects
for o in pool: for o in pool:
# if self.skip_gp and o.type == 'GPENCIL': # if self.skip_gp and o.type == 'GREASEPENCIL':
# continue # continue
# if self.skip_obj and o.type != 'GPENCIL': # if self.skip_obj and o.type != 'GREASEPENCIL':
# continue # continue
if o.type == 'GPENCIL': if o.type == 'GREASEPENCIL':
if o.data.animation_data: if o.data.animation_data:
gp_act = o.data.animation_data.action gp_act = o.data.animation_data.action
if gp_act: if gp_act:
@@ -611,7 +611,7 @@ class GPTB_OT_clear_active_frame(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
obj = context.object obj = context.object
@@ -619,18 +619,18 @@ class GPTB_OT_clear_active_frame(Operator):
if not l: if not l:
self.report({'ERROR'}, 'No layers') self.report({'ERROR'}, 'No layers')
return {'CANCELLED'} return {'CANCELLED'}
f = l.active_frame f = l.current_frame()
if not f: if not f:
self.report({'ERROR'}, 'No active frame') self.report({'ERROR'}, 'No active frame')
return {'CANCELLED'} return {'CANCELLED'}
ct = len(f.strokes) ct = len(f.drawing.strokes)
if not ct: if not ct:
self.report({'ERROR'}, 'Active frame already empty') self.report({'ERROR'}, 'Active frame already empty')
return {'CANCELLED'} return {'CANCELLED'}
for s in reversed(f.strokes): for s in reversed(f.drawing.strokes):
f.strokes.remove(s) f.drawing.strokes.remove(s)
self.report({'INFO'}, f'Cleared active frame ({ct} strokes removed)') self.report({'INFO'}, f'Cleared active frame ({ct} strokes removed)')
return {'FINISHED'} return {'FINISHED'}
@@ -644,7 +644,7 @@ class GPTB_OT_check_canvas_alignement(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
# if lock_axis is 'VIEW' then the draw axis is always aligned # if lock_axis is 'VIEW' then the draw axis is always aligned
return context.object and context.object.type == 'GPENCIL'# and context.scene.tool_settings.gpencil_sculpt.lock_axis != 'VIEW' return context.object and context.object.type == 'GREASEPENCIL'# and context.scene.tool_settings.gpencil_sculpt.lock_axis != 'VIEW'
def execute(self, context): def execute(self, context):
if context.scene.tool_settings.gpencil_sculpt.lock_axis == 'VIEW': if context.scene.tool_settings.gpencil_sculpt.lock_axis == 'VIEW':
@@ -673,7 +673,7 @@ class GPTB_OT_step_select_frames(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
start : bpy.props.IntProperty(name='Start Frame', start : bpy.props.IntProperty(name='Start Frame',
description='Start frame of the step animation', description='Start frame of the step animation',
+6 -6
View File
@@ -8,7 +8,7 @@ def get_layer_list(self, context):
return [('None', 'None','None')] return [('None', 'None','None')]
if not context.object: if not context.object:
return [('None', 'None','None')] return [('None', 'None','None')]
return [(l.info, l.info, '') for l in context.object.data.layers if l != context.object.data.layers.active] return [(l.name, l.name, '') for l in context.object.data.layers if l != context.object.data.layers.active]
# try: # try:
# except: # except:
# return [("", "", "")] # return [("", "", "")]
@@ -40,8 +40,8 @@ class GPTB_OT_duplicate_send_to_layer(Operator) :
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL'\ return context.object and context.object.type == 'GREASEPENCIL'\
and context.space_data.bl_rna.identifier == 'SpaceDopeSheetEditor' and context.space_data.ui_mode == 'GPENCIL' and context.space_data.bl_rna.identifier == 'SpaceDopeSheetEditor' and context.space_data.ui_mode == 'GREASEPENCIL'
# history : bpy.props.StringProperty(default='', options={'SKIP_SAVE'}) # need to have a variable to store (to get it in self) # history : bpy.props.StringProperty(default='', options={'SKIP_SAVE'}) # need to have a variable to store (to get it in self)
@@ -131,7 +131,7 @@ def unregister_keymaps():
def menu_duplicate_and_send_to_layer(self, context): def menu_duplicate_and_send_to_layer(self, context):
if context.space_data.ui_mode == 'GPENCIL': if context.space_data.ui_mode == 'GREASEPENCIL':
self.layout.operator_context = 'INVOKE_REGION_WIN' self.layout.operator_context = 'INVOKE_REGION_WIN'
self.layout.operator('gp.duplicate_send_to_layer', text='Move Keys To Layer').delete_source = True self.layout.operator('gp.duplicate_send_to_layer', text='Move Keys To Layer').delete_source = True
self.layout.operator('gp.duplicate_send_to_layer', text='Copy Keys To Layer') self.layout.operator('gp.duplicate_send_to_layer', text='Copy Keys To Layer')
@@ -148,7 +148,7 @@ def register():
bpy.utils.register_class(cls) bpy.utils.register_class(cls)
register_keymaps() register_keymaps()
bpy.types.DOPESHEET_MT_gpencil_key.append(menu_duplicate_and_send_to_layer) bpy.types.DOPESHEET_MT_key.append(menu_duplicate_and_send_to_layer)
bpy.types.DOPESHEET_MT_context_menu.append(menu_duplicate_and_send_to_layer) bpy.types.DOPESHEET_MT_context_menu.append(menu_duplicate_and_send_to_layer)
@@ -157,7 +157,7 @@ def unregister():
return return
bpy.types.DOPESHEET_MT_context_menu.remove(menu_duplicate_and_send_to_layer) bpy.types.DOPESHEET_MT_context_menu.remove(menu_duplicate_and_send_to_layer)
bpy.types.DOPESHEET_MT_gpencil_key.remove(menu_duplicate_and_send_to_layer) bpy.types.DOPESHEET_MT_key.remove(menu_duplicate_and_send_to_layer)
unregister_keymaps() unregister_keymaps()
for cls in reversed(classes): for cls in reversed(classes):
+1 -1
View File
@@ -10,7 +10,7 @@ class GPTB_OT_jump_gp_keyframe(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
next : BoolProperty( next : BoolProperty(
name="Next GP keyframe", description="Go to next active GP keyframe", name="Next GP keyframe", description="Go to next active GP keyframe",
+53 -53
View File
@@ -30,7 +30,7 @@ def layer_name_build(layer, prefix='', desc='', suffix=''):
prefs = get_addon_prefs() prefs = get_addon_prefs()
sep = prefs.separator sep = prefs.separator
name = old = layer.info name = old = layer.name
pattern = PATTERN.replace('_', sep) # set separator pattern = PATTERN.replace('_', sep) # set separator
@@ -69,7 +69,7 @@ def layer_name_build(layer, prefix='', desc='', suffix=''):
# check if name is available without the increment ending # check if name is available without the increment ending
new = f'{grp}{tag}{name}{sfix}' new = f'{grp}{tag}{name}{sfix}'
layer.info = new layer.name = new
## update name in modifier targets ## update name in modifier targets
if old != new: if old != new:
@@ -78,11 +78,11 @@ def layer_name_build(layer, prefix='', desc='', suffix=''):
# maybe a more elegant way exists to find all objects users ? # maybe a more elegant way exists to find all objects users ?
# update Gpencil modifier targets # update Gpencil modifier targets
for mod in ob_user.grease_pencil_modifiers: for mod in ob_user.modifier:
if not hasattr(mod, 'layer'): if not hasattr(mod, 'layer_filter'):
continue continue
if mod.layer == old: if mod.layer_filter == old:
mod.layer = new mod.layer_filter = new
""" """
def layer_name_build(layer, prefix='', prefix2='', desc='', suffix=''): def layer_name_build(layer, prefix='', prefix2='', desc='', suffix=''):
@@ -93,7 +93,7 @@ def layer_name_build(layer, prefix='', prefix2='', desc='', suffix=''):
prefs = get_addon_prefs() prefs = get_addon_prefs()
sep = prefs.separator sep = prefs.separator
name = layer.info name = layer.name
pattern = pattern.replace('_', sep) # set separator pattern = pattern.replace('_', sep) # set separator
@@ -122,7 +122,7 @@ def layer_name_build(layer, prefix='', prefix2='', desc='', suffix=''):
p4 = sep + suffix.upper().strip() p4 = sep + suffix.upper().strip()
new = f'{p1}{p2}{p3}{p4}' new = f'{p1}{p2}{p3}{p4}'
layer.info = new layer.name = new
""" """
## multi-prefix solution (Caps letters) ## multi-prefix solution (Caps letters)
@@ -172,14 +172,14 @@ class GPTB_OT_layer_name_build(Operator):
def grp_toggle(l, mode='TOGGLE'): def grp_toggle(l, mode='TOGGLE'):
'''take mode in (TOGGLE, GROUP, UNGROUP) ''' '''take mode in (TOGGLE, GROUP, UNGROUP) '''
grp_item_id = ' - ' grp_item_id = ' - '
res = re.search(r'^(\s{1,3}-\s{0,3})(.*)', l.info) res = re.search(r'^(\s{1,3}-\s{0,3})(.*)', l.name)
if not res and mode in ('TOGGLE', 'GROUP'): if not res and mode in ('TOGGLE', 'GROUP'):
# No gpr : add group prefix after stripping all space and dash # No gpr : add group prefix after stripping all space and dash
l.info = grp_item_id + l.info.lstrip(' -') l.name = grp_item_id + l.name.lstrip(' -')
elif res and mode in ('TOGGLE', 'UNGROUP'): elif res and mode in ('TOGGLE', 'UNGROUP'):
# found : delete group prefix # found : delete group prefix
l.info = res.group(2) l.name = res.group(2)
class GPTB_OT_layer_group_toggle(Operator): class GPTB_OT_layer_group_toggle(Operator):
@@ -220,18 +220,18 @@ class GPTB_OT_layer_new_group(Operator):
self.report({'ERROR'}, 'no layer active') self.report({'ERROR'}, 'no layer active')
return {"CANCELLED"} return {"CANCELLED"}
res = re.search(PATTERN, act.info) res = re.search(PATTERN, act.name)
if not res: if not res:
self.report({'ERROR'}, 'Could not create a group name, create a layer manually') self.report({'ERROR'}, 'Could not create a group name, create a layer manually')
return {"CANCELLED"} return {"CANCELLED"}
name = res.group('name').strip(' -') name = res.group('name').strip(' -')
if not name: if not name:
self.report({'ERROR'}, f'No name found in {act.info}') self.report({'ERROR'}, f'No name found in {act.name}')
return {"CANCELLED"} return {"CANCELLED"}
if name in [l.info.strip(' -') for l in gpl]: if name in [l.name.strip(' -') for l in gpl]:
self.report({'WARNING'}, f'Name already exists: {act.info}') self.report({'WARNING'}, f'Name already exists: {act.name}')
return {"FINISHED"} return {"FINISHED"}
grp_toggle(act, mode='GROUP') grp_toggle(act, mode='GROUP')
@@ -261,9 +261,9 @@ def build_layers_targets_from_dopesheet(context):
if dopeset.show_only_selected: if dopeset.show_only_selected:
pool = [o for o in context.selected_objects if o.type == 'GPENCIL'] pool = [o for o in context.selected_objects if o.type == 'GREASEPENCIL']
else: else:
pool = [o for o in context.scene.objects if o.type == 'GPENCIL'] pool = [o for o in context.scene.objects if o.type == 'GREASEPENCIL']
if not dopeset.show_hidden: if not dopeset.show_hidden:
pool = [o for o in pool if o.visible_get()] pool = [o for o in pool if o.visible_get()]
@@ -272,7 +272,7 @@ def build_layers_targets_from_dopesheet(context):
# apply search filter # apply search filter
if dopeset.filter_text: if dopeset.filter_text:
layer_pool = [l for l in layer_pool if (dopeset.filter_text.lower() in l.info.lower()) ^ dopeset.use_filter_invert] layer_pool = [l for l in layer_pool if (dopeset.filter_text.lower() in l.name.lower()) ^ dopeset.use_filter_invert]
return layer_pool return layer_pool
@@ -292,7 +292,7 @@ class GPTB_OT_select_set_same_prefix(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
mode : EnumProperty(default='SELECT', options={'SKIP_SAVE'}, mode : EnumProperty(default='SELECT', options={'SKIP_SAVE'},
items=( items=(
@@ -330,35 +330,35 @@ class GPTB_OT_select_set_same_prefix(Operator):
self.report({'ERROR'}, 'No active layer to base action') self.report({'ERROR'}, 'No active layer to base action')
return {"CANCELLED"} return {"CANCELLED"}
print(f'Select/Set ref layer: {gp.name} > {gp.layers.active.info}') print(f'Select/Set ref layer: {gp.name} > {gp.layers.active.name}')
res = re.search(PATTERN, act.info) res = re.search(PATTERN, act.name)
if not res: if not res:
self.report({'ERROR'}, f'Error scanning {act.info}') self.report({'ERROR'}, f'Error scanning {act.name}')
return {"CANCELLED"} return {"CANCELLED"}
namespace = res.group('tag') namespace = res.group('tag')
if not namespace: if not namespace:
self.report({'WARNING'}, f'No prefix detected in {act.info} with separator {sep}') self.report({'WARNING'}, f'No prefix detected in {act.name} with separator {sep}')
return {"CANCELLED"} return {"CANCELLED"}
if self.mode == 'SELECT': if self.mode == 'SELECT':
## with split ## with split
# namespace = act.info.split(sep,1)[0] # namespace = act.name.split(sep,1)[0]
# namespace_bool_list = [l.info.split(sep,1)[0] == namespace for l in gpl] # namespace_bool_list = [l.name.split(sep,1)[0] == namespace for l in gpl]
## with reg # only active ## with reg # only active
# namespace_bool_list = [l.info.split(sep,1)[0] + sep == namespace for l in gpl] # namespace_bool_list = [l.name.split(sep,1)[0] + sep == namespace for l in gpl]
# gpl.foreach_set('select', namespace_bool_list) # gpl.foreach_set('select', namespace_bool_list)
## don't work Need Foreach set per gp ## don't work Need Foreach set per gp
# for l in pool: # for l in pool:
# l.select = l.info.split(sep,1)[0] + sep == namespace # l.select = l.name.split(sep,1)[0] + sep == namespace
for gp, layers in gp_dic.items(): for gp, layers in gp_dic.items():
# check namespace + restrict selection to visible layers according to filters # check namespace + restrict selection to visible layers according to filters
# TODO : Should use the regex pattern to detect and compare r.group('tag') # TODO : Should use the regex pattern to detect and compare r.group('tag')
namespace_bool_list = [(l in layers) and (l.info.split(sep,1)[0] + sep == namespace) for l in gp.layers] namespace_bool_list = [(l in layers) and (l.name.split(sep,1)[0] + sep == namespace) for l in gp.layers]
gp.layers.foreach_set('select', namespace_bool_list) gp.layers.foreach_set('select', namespace_bool_list)
elif self.mode == 'SET': elif self.mode == 'SET':
@@ -380,7 +380,7 @@ class GPTB_OT_select_set_same_color(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
mode : EnumProperty(default='SELECT', options={'SKIP_SAVE'}, mode : EnumProperty(default='SELECT', options={'SKIP_SAVE'},
items=( items=(
@@ -415,7 +415,7 @@ class GPTB_OT_select_set_same_color(Operator):
self.report({'ERROR'}, 'No active layer to base action') self.report({'ERROR'}, 'No active layer to base action')
return {"CANCELLED"} return {"CANCELLED"}
print(f'Select/Set ref layer: {gp.name} > {gp.layers.active.info}') print(f'Select/Set ref layer: {gp.name} > {gp.layers.active.name}')
color = act.channel_color color = act.channel_color
if self.mode == 'SELECT': if self.mode == 'SELECT':
## NEED FOREACH TO APPLY SELECT ## NEED FOREACH TO APPLY SELECT
@@ -426,7 +426,7 @@ class GPTB_OT_select_set_same_color(Operator):
# On multiple objects -- don't work, need foreach # On multiple objects -- don't work, need foreach
# for l in pool: # for l in pool:
# print(l.id_data.name, l.info, l.channel_color == act.channel_color) # print(l.id_data.name, l.name, l.channel_color == act.channel_color)
# l.select = l.channel_color == act.channel_color # l.select = l.channel_color == act.channel_color
""" """
@@ -463,38 +463,38 @@ def replace_layer_name(target, replacement, selected_only=True, prefix_only=True
gpl = bpy.context.object.data.layers gpl = bpy.context.object.data.layers
if selected_only: if selected_only:
lays = [l for l in gpl if l.select] # exclude : l.info != 'background' lays = [l for l in gpl if l.select] # exclude : l.name != 'background'
else: else:
lays = [l for l in gpl] # exclude : if l.info != 'background' lays = [l for l in gpl] # exclude : if l.name != 'background'
ct = 0 ct = 0
for l in lays: for l in lays:
old = l.info old = l.name
if regex: if regex:
new = re.sub(target, replacement, l.info) new = re.sub(target, replacement, l.name)
if old != new: if old != new:
l.info = new l.name = new
print('rename:', old, '-->', new) print('rename:', old, '-->', new)
ct += 1 ct += 1
continue continue
if prefix_only: if prefix_only:
if not sep in l.info: if not sep in l.name:
# only if separator exists # only if separator exists
continue continue
splited = l.info.split(sep) splited = l.name.split(sep)
prefix = splited[0] prefix = splited[0]
new_prefix = prefix.replace(target, replacement) new_prefix = prefix.replace(target, replacement)
if prefix != new_prefix: if prefix != new_prefix:
splited[0] = new_prefix splited[0] = new_prefix
l.info = sep.join(splited) l.name = sep.join(splited)
print('rename:', old, '-->', l.info) print('rename:', old, '-->', l.name)
ct += 1 ct += 1
else: else:
new = l.info.replace(target, replacement) new = l.name.replace(target, replacement)
if old != new: if old != new:
l.info = new l.name = new
print('rename:', old, '-->', new) print('rename:', old, '-->', new)
ct += 1 ct += 1
return ct return ct
@@ -507,7 +507,7 @@ class GPTB_OT_rename_gp_layer(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
find: StringProperty(name="Find", description="Name to replace", default="", maxlen=0, options={'ANIMATABLE'}, subtype='NONE') find: StringProperty(name="Find", description="Name to replace", default="", maxlen=0, options={'ANIMATABLE'}, subtype='NONE')
replace: StringProperty(name="Repl", description="New name placed", default="", maxlen=0, options={'ANIMATABLE'}, subtype='NONE') replace: StringProperty(name="Repl", description="New name placed", default="", maxlen=0, options={'ANIMATABLE'}, subtype='NONE')
@@ -548,7 +548,7 @@ class GPTB_OT_rename_gp_layer(Operator):
## --- UI layer panel--- ## --- UI layer panel---
def layer_name_builder_ui(self, context): def layer_name_builder_ui(self, context):
'''appended to DATA_PT_gpencil_layers''' '''appended to DATA_PT_grease_pencil_layers'''
prefs = get_addon_prefs() prefs = get_addon_prefs()
if not prefs.show_prefix_buttons: if not prefs.show_prefix_buttons:
@@ -557,7 +557,7 @@ def layer_name_builder_ui(self, context):
return return
layout = self.layout layout = self.layout
# {'EDIT_GPENCIL', 'PAINT_GPENCIL','SCULPT_GPENCIL','WEIGHT_GPENCIL', 'VERTEX_GPENCIL'} # {'EDIT_GREASE_PENCIL', 'PAINT_GREASE_PENCIL','SCULPT_GREASE_PENCIL','WEIGHT_GREASE_PENCIL', 'VERTEX_GPENCIL'}
# layout.separator() # layout.separator()
col = layout.column() col = layout.column()
@@ -633,7 +633,7 @@ def gpencil_dopesheet_header(self, context):
'''to append in DOPESHEET_HT_header''' '''to append in DOPESHEET_HT_header'''
layout = self.layout layout = self.layout
st = context.space_data st = context.space_data
if st.mode != 'GPENCIL': if st.mode != 'GREASEPENCIL':
return return
row = layout.row(align=True) row = layout.row(align=True)
@@ -653,7 +653,7 @@ def gpencil_layer_dropdown_menu(self, context):
def obj_layer_name_callback(): def obj_layer_name_callback():
'''assign layer name properties so user an tweak it''' '''assign layer name properties so user an tweak it'''
ob = bpy.context.object ob = bpy.context.object
if not ob or ob.type != 'GPENCIL': if not ob or ob.type != 'GREASEPENCIL':
return return
if not ob.data.layers.active: if not ob.data.layers.active:
return return
@@ -663,7 +663,7 @@ def obj_layer_name_callback():
for l in ob.data.layers: for l in ob.data.layers:
l.select = l == ob.data.layers.active l.select = l == ob.data.layers.active
res = re.search(PATTERN, ob.data.layers.active.info.strip()) res = re.search(PATTERN, ob.data.layers.active.name.strip())
if not res: if not res:
return return
if not res.group('name'): if not res.group('name'):
@@ -736,7 +736,7 @@ class GPTB_OT_add_gp_layer_with_rename(Operator):
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
add_layer(context) add_layer(context)
@@ -750,7 +750,7 @@ class GPTB_OT_add_gp_layer(Operator):
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
add_layer(context) add_layer(context)
@@ -776,7 +776,7 @@ def register_keymaps():
##---# F2 rename calls ##---# F2 rename calls
## Direct rename active layer in Paint mode ## Direct rename active layer in Paint mode
km = addon.keymaps.new(name = "Grease Pencil Stroke Paint Mode", space_type = "EMPTY") km = addon.keymaps.new(name = "Grease Pencil Paint Mode", space_type = "EMPTY")
kmi = km.keymap_items.new('wm.call_panel', type='F2', value='PRESS') kmi = km.keymap_items.new('wm.call_panel', type='F2', value='PRESS')
kmi.properties.name = 'GPTB_PT_layer_name_ui' kmi.properties.name = 'GPTB_PT_layer_name_ui'
kmi.properties.keep_open = False kmi.properties.keep_open = False
@@ -817,7 +817,7 @@ def register():
for cls in classes: for cls in classes:
bpy.utils.register_class(cls) bpy.utils.register_class(cls)
bpy.types.DATA_PT_gpencil_layers.prepend(layer_name_builder_ui) bpy.types.DATA_PT_grease_pencil_layers.prepend(layer_name_builder_ui)
bpy.types.DOPESHEET_HT_header.append(gpencil_dopesheet_header) bpy.types.DOPESHEET_HT_header.append(gpencil_dopesheet_header)
bpy.types.GPENCIL_MT_layer_context_menu.append(gpencil_layer_dropdown_menu) bpy.types.GPENCIL_MT_layer_context_menu.append(gpencil_layer_dropdown_menu)
bpy.app.handlers.load_post.append(subscribe_layer_change_handler) bpy.app.handlers.load_post.append(subscribe_layer_change_handler)
@@ -831,7 +831,7 @@ def unregister():
bpy.app.handlers.load_post.remove(subscribe_layer_change_handler) bpy.app.handlers.load_post.remove(subscribe_layer_change_handler)
bpy.types.GPENCIL_MT_layer_context_menu.remove(gpencil_layer_dropdown_menu) bpy.types.GPENCIL_MT_layer_context_menu.remove(gpencil_layer_dropdown_menu)
bpy.types.DOPESHEET_HT_header.remove(gpencil_dopesheet_header) bpy.types.DOPESHEET_HT_header.remove(gpencil_dopesheet_header)
bpy.types.DATA_PT_gpencil_layers.remove(layer_name_builder_ui) bpy.types.DATA_PT_grease_pencil_layers.remove(layer_name_builder_ui)
for cls in reversed(classes): for cls in reversed(classes):
bpy.utils.unregister_class(cls) bpy.utils.unregister_class(cls)
+1 -1
View File
@@ -127,7 +127,7 @@ addon_keymaps = []
def register_keymap(): def register_keymap():
addon = bpy.context.window_manager.keyconfigs.addon addon = bpy.context.window_manager.keyconfigs.addon
km = addon.keymaps.new(name = "Grease Pencil Stroke Paint Mode", space_type = "EMPTY") km = addon.keymaps.new(name = "Grease Pencil Paint Mode", space_type = "EMPTY")
kmi = km.keymap_items.new('gp.layer_nav', type='PAGE_UP', value='PRESS') kmi = km.keymap_items.new('gp.layer_nav', type='PAGE_UP', value='PRESS')
kmi.properties.direction = 'UP' kmi.properties.direction = 'UP'
+12 -12
View File
@@ -14,7 +14,7 @@ class GP_OT_pick_closest_layer(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' and context.mode == 'PAINT_GPENCIL' return context.object and context.object.type == 'GREASEPENCIL' and context.mode == 'PAINT_GREASE_PENCIL'
stroke_filter : bpy.props.EnumProperty(name='Target', stroke_filter : bpy.props.EnumProperty(name='Target',
default='STROKE', default='STROKE',
@@ -47,7 +47,7 @@ class GP_OT_pick_closest_layer(Operator):
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
if context.object.data.layers.active: if context.object.data.layers.active:
layout.label(text=f'Layer: {context.object.data.layers.active.info}') layout.label(text=f'Layer: {context.object.data.layers.active.name}')
layout.prop(self, 'stroke_filter') layout.prop(self, 'stroke_filter')
def modal(self, context, event): def modal(self, context, event):
@@ -74,31 +74,31 @@ class GP_OT_pick_closest_layer(Operator):
self.inv_mat = self.ob.matrix_world.inverted() self.inv_mat = self.ob.matrix_world.inverted()
self.point_pair = [] self.point_pair = []
if gp.use_multiedit: if context.scene.tool_settings.use_grease_pencil_multi_frame_editing:
for layer_id, l in enumerate(gp.layers): for layer_id, l in enumerate(gp.layers):
if l.hide:# l.lock or if l.hide: # l.lock or
continue continue
for f in l.frames: for f in l.frames:
if not f.select: if not f.select:
continue continue
for s in f.strokes: for s in f.drawing.strokes:
if self.stroke_filter == 'STROKE' and not self.ob.data.materials[s.material_index].grease_pencil.show_stroke: if self.stroke_filter == 'STROKE' and not self.ob.data.materials[s.material_index].grease_pencil.show_stroke:
continue continue
elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill: elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill:
continue continue
self.point_pair += [(Vector((*location_to_region(mat @ p.co), 0)), layer_id) for p in s.points] self.point_pair += [(Vector((*location_to_region(mat @ p.position), 0)), layer_id) for p in s.points]
else: else:
# [s for l in gp.layers if not l.lock and not l.hide for s in l.active_frame.stokes] # [s for l in gp.layers if not l.lock and not l.hide for s in l.current_frame().stokes]
for layer_id, l in enumerate(gp.layers): for layer_id, l in enumerate(gp.layers):
if l.hide or not l.active_frame:# l.lock or if l.hide or not l.current_frame(): # l.lock or
continue continue
for s in l.active_frame.strokes: for s in l.current_frame().drawing.strokes:
if self.stroke_filter == 'STROKE' and not self.ob.data.materials[s.material_index].grease_pencil.show_stroke: if self.stroke_filter == 'STROKE' and not self.ob.data.materials[s.material_index].grease_pencil.show_stroke:
continue continue
elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill: elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill:
continue continue
self.point_pair += [(Vector((*location_to_region(mat @ p.co), 0)), layer_id) for p in s.points] self.point_pair += [(Vector((*location_to_region(mat @ p.position), 0)), layer_id) for p in s.points]
if not self.point_pair: if not self.point_pair:
self.report({'ERROR'}, 'No stroke found, maybe layers are locked or hidden') self.report({'ERROR'}, 'No stroke found, maybe layers are locked or hidden')
@@ -117,7 +117,7 @@ class GP_OT_pick_closest_layer(Operator):
## debug show trigger time ## debug show trigger time
# print(f'Trigger time {time() - self.t0:.3f}') # print(f'Trigger time {time() - self.t0:.3f}')
# print(f'Search time {time() - t1:.3f}') # print(f'Search time {time() - t1:.3f}')
self.report({'INFO'}, f'Layer: {self.ob.data.layers.active.info}') self.report({'INFO'}, f'Layer: {self.ob.data.layers.active.name}')
return {'FINISHED'} return {'FINISHED'}
@@ -125,7 +125,7 @@ class GP_OT_pick_closest_layer(Operator):
addon_keymaps = [] addon_keymaps = []
def register_keymaps(): def register_keymaps():
addon = bpy.context.window_manager.keyconfigs.addon addon = bpy.context.window_manager.keyconfigs.addon
km = addon.keymaps.new(name = "Grease Pencil Stroke Paint Mode", space_type = "EMPTY", region_type='WINDOW') km = addon.keymaps.new(name = "Grease Pencil Paint Mode", space_type = "EMPTY", region_type='WINDOW')
kmi = km.keymap_items.new( kmi = km.keymap_items.new(
# name="", # name="",
+9 -9
View File
@@ -11,7 +11,7 @@ from . import utils
# return [('None', 'None','None')] # return [('None', 'None','None')]
# if not context.object: # if not context.object:
# return [('None', 'None','None')] # return [('None', 'None','None')]
# return [(l.info, l.info, '') for l in context.object.data.layers] # if l != context.object.data.layers.active # return [(l.name, l.name, '') for l in context.object.data.layers] # if l != context.object.data.layers.active
## in Class ## in Class
# bl_property = "layers_enum" # bl_property = "layers_enum"
@@ -39,7 +39,7 @@ class GPTB_OT_move_material_to_layer(Operator) :
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def invoke(self, context, event): def invoke(self, context, event):
if self.layer_name: if self.layer_name:
@@ -72,8 +72,8 @@ class GPTB_OT_move_material_to_layer(Operator) :
icon = 'GREASEPENCIL' if l == context.object.data.layers.active else 'BLANK1' icon = 'GREASEPENCIL' if l == context.object.data.layers.active else 'BLANK1'
row = col.row() row = col.row()
row.alignment = 'LEFT' row.alignment = 'LEFT'
op = col.operator('gp.move_material_to_layer', text=l.info, icon=icon, emboss=False) op = col.operator('gp.move_material_to_layer', text=l.name, icon=icon, emboss=False)
op.layer_name = l.info op.layer_name = l.name
op.copy = self.copy op.copy = self.copy
def execute(self, context): def execute(self, context):
@@ -82,7 +82,7 @@ class GPTB_OT_move_material_to_layer(Operator) :
return {'CANCELLED'} return {'CANCELLED'}
## Active + selection ## Active + selection
pool = [o for o in bpy.context.selected_objects if o.type == 'GPENCIL'] pool = [o for o in bpy.context.selected_objects if o.type == 'GREASEPENCIL']
if not context.object in pool: if not context.object in pool:
pool.append(context.object) pool.append(context.object)
@@ -116,7 +116,7 @@ class GPTB_OT_move_material_to_layer(Operator) :
continue continue
for f in l.frames: for f in l.frames:
## skip if no stroke has active material ## skip if no stroke has active material
if not next((s for s in f.strokes if s.material_index == mat_index), None): if not next((s for s in f.drawing.strokes if s.material_index == mat_index), None):
continue continue
## Get/Create a destination frame and keep a reference to it ## Get/Create a destination frame and keep a reference to it
if not (dest_key := key_dict.get(f.frame_number)): if not (dest_key := key_dict.get(f.frame_number)):
@@ -126,7 +126,7 @@ class GPTB_OT_move_material_to_layer(Operator) :
print(f'{ob.name} : frame {f.frame_number}') print(f'{ob.name} : frame {f.frame_number}')
## Replicate strokes in dest_keys ## Replicate strokes in dest_keys
stroke_to_delete = [] stroke_to_delete = []
for s in f.strokes: for s in f.drawing.strokes:
if s.material_index == mat_index: if s.material_index == mat_index:
utils.copy_stroke_to_frame(s, dest_key) utils.copy_stroke_to_frame(s, dest_key)
stroke_to_delete.append(s) stroke_to_delete.append(s)
@@ -142,7 +142,7 @@ class GPTB_OT_move_material_to_layer(Operator) :
## Remove from source frame (f) ## Remove from source frame (f)
if not self.copy: if not self.copy:
for s in reversed(stroke_to_delete): for s in reversed(stroke_to_delete):
f.strokes.remove(s) f.drawing.strokes.remove(s)
## ? Remove frame if layer is empty ? -> probably not, will show previous frame ## ? Remove frame if layer is empty ? -> probably not, will show previous frame
@@ -165,7 +165,7 @@ class GPTB_OT_move_material_to_layer(Operator) :
# def menu_duplicate_and_send_to_layer(self, context): # def menu_duplicate_and_send_to_layer(self, context):
# if context.space_data.ui_mode == 'GPENCIL': # if context.space_data.ui_mode == 'GREASEPENCIL':
# self.layout.operator_context = 'INVOKE_REGION_WIN' # self.layout.operator_context = 'INVOKE_REGION_WIN'
# self.layout.operator('gp.duplicate_send_to_layer', text='Move Keys To Layer').delete_source = True # self.layout.operator('gp.duplicate_send_to_layer', text='Move Keys To Layer').delete_source = True
# self.layout.operator('gp.duplicate_send_to_layer', text='Copy Keys To Layer') # self.layout.operator('gp.duplicate_send_to_layer', text='Copy Keys To Layer')
+23 -23
View File
@@ -33,20 +33,20 @@ class GP_OT_pick_closest_material(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' and context.mode == 'PAINT_GPENCIL' return context.object and context.object.type == 'GREASEPENCIL' and context.mode == 'PAINT_GREASE_PENCIL'
fill_only : bpy.props.BoolProperty(default=False, options={'SKIP_SAVE'}) fill_only : bpy.props.BoolProperty(default=False, options={'SKIP_SAVE'})
def filter_stroke(self, context): def filter_stroke(self, context):
# get stroke under mouse using kdtree # get stroke under mouse using kdtree
point_pair = [(p.co, s) for s in self.stroke_list for p in s.points] # local space point_pair = [(p.position, s) for s in self.stroke_list for p in s.points] # local space
kd = mathutils.kdtree.KDTree(len(point_pair)) kd = mathutils.kdtree.KDTree(len(point_pair))
for i, pair in enumerate(point_pair): for i, pair in enumerate(point_pair):
kd.insert(pair[0], i) kd.insert(pair[0], i)
kd.balance() kd.balance()
## Get 3D coordinate on drawing plane according to mouse 2d.co on flat 2d drawing ## Get 3D coordinate on drawing plane according to mouse 2d.position on flat 2d drawing
_ob, hit, _plane_no = get_3d_coord_on_drawing_plane_from_2d(context, self.init_mouse) _ob, hit, _plane_no = get_3d_coord_on_drawing_plane_from_2d(context, self.init_mouse)
if not hit: if not hit:
@@ -62,7 +62,7 @@ class GP_OT_pick_closest_material(Operator):
## find point index in stroke ## find point index in stroke
self.idx = None self.idx = None
for i, p in enumerate(s.points): for i, p in enumerate(s.points):
if p.co == co: if p.position == co:
self.idx = i self.idx = i
break break
@@ -77,22 +77,22 @@ class GP_OT_pick_closest_material(Operator):
self.stroke_list = [] self.stroke_list = []
self.inv_mat = self.ob.matrix_world.inverted() self.inv_mat = self.ob.matrix_world.inverted()
if self.gp.use_multiedit: if context.scene.tool_settings.use_grease_pencil_multi_frame_editing:
for l in self.gp.layers: for l in self.gp.layers:
if l.hide:# l.lock or if l.hide:# l.lock or
continue continue
for f in l.frames: for f in l.frames:
if not f.select: if not f.select:
continue continue
for s in f.strokes: for s in f.drawing.strokes:
self.stroke_list.append(s) self.stroke_list.append(s)
else: else:
# [s for l in self.gp.layers if not l.lock and not l.hide for s in l.active_frame.stokes] # [s for l in self.gp.layers if not l.lock and not l.hide for s in l.current_frame().stokes]
for l in self.gp.layers: for l in self.gp.layers:
if l.hide or not l.active_frame:# l.lock or if l.hide or not l.current_frame():# l.lock or
continue continue
for s in l.active_frame.strokes: for s in l.current_frame().drawing.strokes:
self.stroke_list.append(s) self.stroke_list.append(s)
if self.fill_only: if self.fill_only:
@@ -116,8 +116,8 @@ class GP_OT_pick_closest_material(Operator):
self.report({'WARNING'}, 'No coord found') self.report({'WARNING'}, 'No coord found')
return {'CANCELLED'} return {'CANCELLED'}
self.depth = self.ob.matrix_world @ self.stroke.points[self.idx].co self.depth = self.ob.matrix_world @ self.stroke.points[self.idx].position
self.init_pos = [p.co.copy() for p in self.stroke.points] # need a copy otherwise vector is updated self.init_pos = [p.position.copy() for p in self.stroke.points] # need a copy otherwise vector is updated
## directly use world position ? ## directly use world position ?
# self.pos_world = [self.ob.matrix_world @ co for co in self.init_pos] # self.pos_world = [self.ob.matrix_world @ co for co in self.init_pos]
self.pos_2d = [location_to_region(self.ob.matrix_world @ co) for co in self.init_pos] self.pos_2d = [location_to_region(self.ob.matrix_world @ co) for co in self.init_pos]
@@ -144,7 +144,7 @@ class GP_OT_pick_closest_material(Operator):
# if event.type in {'RIGHTMOUSE', 'ESC'}: # if event.type in {'RIGHTMOUSE', 'ESC'}:
# # for i, p in enumerate(self.stroke.points): # reset position # # for i, p in enumerate(self.stroke.points): # reset position
# # self.stroke.points[i].co = self.init_pos[i] # # self.stroke.points[i].position = self.init_pos[i]
# context.area.tag_redraw() # context.area.tag_redraw()
# return {'CANCELLED'} # return {'CANCELLED'}
@@ -159,7 +159,7 @@ class GP_OT_pick_closest_material(Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' and context.mode == 'PAINT_GPENCIL' return context.object and context.object.type == 'GREASEPENCIL' and context.mode == 'PAINT_GREASE_PENCIL'
# fill_only : bpy.props.BoolProperty(default=False, options={'SKIP_SAVE'}) # fill_only : bpy.props.BoolProperty(default=False, options={'SKIP_SAVE'})
stroke_filter : bpy.props.EnumProperty(default='FILL', stroke_filter : bpy.props.EnumProperty(default='FILL',
@@ -172,7 +172,7 @@ class GP_OT_pick_closest_material(Operator):
def filter_stroke(self, context): def filter_stroke(self, context):
# get stroke under mouse using kdtree # get stroke under mouse using kdtree
point_pair = [(p.co, s) for s in self.stroke_list for p in s.points] # local space point_pair = [(p.position, s) for s in self.stroke_list for p in s.points] # local space
kd = mathutils.kdtree.KDTree(len(point_pair)) kd = mathutils.kdtree.KDTree(len(point_pair))
for i, pair in enumerate(point_pair): for i, pair in enumerate(point_pair):
@@ -195,7 +195,7 @@ class GP_OT_pick_closest_material(Operator):
## find point index in stroke ## find point index in stroke
self.idx = None self.idx = None
for i, p in enumerate(s.points): for i, p in enumerate(s.points):
if p.co == co: if p.position == co:
self.idx = i self.idx = i
break break
@@ -233,22 +233,22 @@ class GP_OT_pick_closest_material(Operator):
self.stroke_list = [] self.stroke_list = []
self.inv_mat = self.ob.matrix_world.inverted() self.inv_mat = self.ob.matrix_world.inverted()
if gp.use_multiedit: if context.scene.tool_settings.use_grease_pencil_multi_frame_editing:
for l in gp.layers: for l in gp.layers:
if l.hide:# l.lock or if l.hide:# l.lock or
continue continue
for f in l.frames: for f in l.frames:
if not f.select: if not f.select:
continue continue
for s in f.strokes: for s in f.drawing.strokes:
self.stroke_list.append(s) self.stroke_list.append(s)
else: else:
# [s for l in gp.layers if not l.lock and not l.hide for s in l.active_frame.stokes] # [s for l in gp.layers if not l.lock and not l.hide for s in l.current_frame().stokes]
for l in gp.layers: for l in gp.layers:
if l.hide or not l.active_frame:# l.lock or if l.hide or not l.current_frame():# l.lock or
continue continue
for s in l.active_frame.strokes: for s in l.current_frame().drawing.strokes:
self.stroke_list.append(s) self.stroke_list.append(s)
if self.stroke_filter == 'FILL': if self.stroke_filter == 'FILL':
@@ -274,8 +274,8 @@ class GP_OT_pick_closest_material(Operator):
self.report({'WARNING'}, 'No coord found') self.report({'WARNING'}, 'No coord found')
return {'CANCELLED'} return {'CANCELLED'}
# self.depth = self.ob.matrix_world @ stroke.points[self.idx].co # self.depth = self.ob.matrix_world @ stroke.points[self.idx].position
# self.init_pos = [p.co.copy() for p in stroke.points] # need a copy otherwise vector is updated # self.init_pos = [p.position.copy() for p in stroke.points] # need a copy otherwise vector is updated
# self.pos_2d = [location_to_region(self.ob.matrix_world @ co) for co in self.init_pos] # self.pos_2d = [location_to_region(self.ob.matrix_world @ co) for co in self.init_pos]
# self.plen = len(stroke.points) # self.plen = len(stroke.points)
@@ -291,7 +291,7 @@ addon_keymaps = []
def register_keymaps(): def register_keymaps():
addon = bpy.context.window_manager.keyconfigs.addon addon = bpy.context.window_manager.keyconfigs.addon
# km = addon.keymaps.new(name = "Grease Pencil Stroke Paint (Draw brush)", space_type = "EMPTY", region_type='WINDOW') # km = addon.keymaps.new(name = "Grease Pencil Stroke Paint (Draw brush)", space_type = "EMPTY", region_type='WINDOW')
# km = addon.keymaps.new(name = "Grease Pencil Stroke Paint Mode", space_type = "EMPTY", region_type='WINDOW') # km = addon.keymaps.new(name = "Grease Pencil Paint Mode", space_type = "EMPTY", region_type='WINDOW')
km = addon.keymaps.new(name = "Grease Pencil Stroke Paint (Fill)", space_type = "EMPTY", region_type='WINDOW') km = addon.keymaps.new(name = "Grease Pencil Stroke Paint (Fill)", space_type = "EMPTY", region_type='WINDOW')
kmi = km.keymap_items.new( kmi = km.keymap_items.new(
# name="", # name="",
+11 -11
View File
@@ -42,7 +42,7 @@ class GPTB_OT_load_default_palette(bpy.types.Operator):
# path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="") # path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="")
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
# Start Clean (delete unuesed sh*t) # Start Clean (delete unuesed sh*t)
@@ -82,7 +82,7 @@ class GPTB_OT_load_palette(bpy.types.Operator, ImportHelper):
# path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="") # path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="")
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
filename_ext = '.json' filename_ext = '.json'
@@ -110,7 +110,7 @@ class GPTB_OT_save_palette(bpy.types.Operator, ExportHelper):
# path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="") # path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="")
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
filter_glob: bpy.props.StringProperty(default='*.json', options={'HIDDEN'})#*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.bmp filter_glob: bpy.props.StringProperty(default='*.json', options={'HIDDEN'})#*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.bmp
@@ -169,7 +169,7 @@ def load_blend_palette(context, filepath):
print(f'-- import palette from : {filepath} --') print(f'-- import palette from : {filepath} --')
for ob in context.selected_objects: for ob in context.selected_objects:
if ob.type != 'GPENCIL': if ob.type != 'GREASEPENCIL':
print(f'{ob.name} not a GP object') print(f'{ob.name} not a GP object')
continue continue
@@ -224,7 +224,7 @@ class GPTB_OT_load_blend_palette(bpy.types.Operator, ImportHelper):
# path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="") # path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="")
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
filename_ext = '.blend' filename_ext = '.blend'
@@ -252,7 +252,7 @@ class GPTB_OT_copy_active_to_selected_palette(bpy.types.Operator):
# path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="") # path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="")
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def execute(self, context): def execute(self, context):
ob = context.object ob = context.object
@@ -260,7 +260,7 @@ class GPTB_OT_copy_active_to_selected_palette(bpy.types.Operator):
self.report({'ERROR'}, 'No materials to transfer') self.report({'ERROR'}, 'No materials to transfer')
return {"CANCELLED"} return {"CANCELLED"}
selection = [o for o in context.selected_objects if o.type == 'GPENCIL' and o != ob] selection = [o for o in context.selected_objects if o.type == 'GREASEPENCIL' and o != ob]
if not selection: if not selection:
self.report({'ERROR'}, 'Need to have other Grease pencil objects selected to receive active object materials') self.report({'ERROR'}, 'Need to have other Grease pencil objects selected to receive active object materials')
@@ -313,7 +313,7 @@ class GPTB_OT_clean_material_stack(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
def invoke(self, context, event): def invoke(self, context, event):
self.ob = context.object self.ob = context.object
@@ -354,7 +354,7 @@ class GPTB_OT_clean_material_stack(bpy.types.Operator):
import re import re
diff_ct = 0 diff_ct = 0
todel = [] todel = []
if ob.type != 'GPENCIL': if ob.type != 'GREASEPENCIL':
return return
if not hasattr(ob, 'material_slots'): if not hasattr(ob, 'material_slots'):
return return
@@ -410,7 +410,7 @@ class GPTB_OT_clean_material_stack(bpy.types.Operator):
# iterate in all strokes and replace with new_mat_id # iterate in all strokes and replace with new_mat_id
for l in ob.data.layers: for l in ob.data.layers:
for f in l.frames: for f in l.frames:
for s in f.strokes: for s in f.drawing.strokes:
if s.material_index == i: if s.material_index == i:
s.material_index = new_mat_id s.material_index = new_mat_id
@@ -427,7 +427,7 @@ class GPTB_OT_clean_material_stack(bpy.types.Operator):
# if self.skip_binded_empty_slots: # if self.skip_binded_empty_slots:
# for l in ob.data.layers: # for l in ob.data.layers:
# for f in l.frames: # for f in l.frames:
# for s in f.strokes: # for s in f.drawing.strokes:
# if s.material_index == i: # if s.material_index == i:
# is_binded = True # is_binded = True
# break # break
+2 -2
View File
@@ -45,7 +45,7 @@ class GPTB_OT_import_obj_palette(Operator):
def execute(self, context): def execute(self, context):
## get targets ## get targets
selection = [o for o in context.selected_objects if o.type == 'GPENCIL'] selection = [o for o in context.selected_objects if o.type == 'GREASEPENCIL']
if not selection: if not selection:
self.report({'ERROR'}, 'Need to have at least one GP object selected in scene') self.report({'ERROR'}, 'Need to have at least one GP object selected in scene')
return {"CANCELLED"} return {"CANCELLED"}
@@ -98,7 +98,7 @@ class GPTB_OT_import_obj_palette(Operator):
return {"CANCELLED"} return {"CANCELLED"}
for i in range(len(linked_objs))[::-1]: # reversed(range(len(l))) / range(len(l))[::-1] for i in range(len(linked_objs))[::-1]: # reversed(range(len(l))) / range(len(l))[::-1]
if linked_objs[i].type != 'GPENCIL': if linked_objs[i].type != 'GREASEPENCIL':
print(f'{linked_objs[i].name} type is "{linked_objs[i].type}"') print(f'{linked_objs[i].name} type is "{linked_objs[i].type}"')
bpy.data.objects.remove(linked_objs.pop(i)) bpy.data.objects.remove(linked_objs.pop(i))
+5 -5
View File
@@ -74,7 +74,7 @@ class GPT_OT_auto_tint_gp_layers(bpy.types.Operator):
# namespace_order # namespace_order
namespaces=[] namespaces=[]
for l in gpl: for l in gpl:
ns= l.info.lower().split(separator, 1)[0] ns= l.name.lower().split(separator, 1)[0]
if ns not in namespaces: if ns not in namespaces:
namespaces.append(ns) namespaces.append(ns)
@@ -88,14 +88,14 @@ class GPT_OT_auto_tint_gp_layers(bpy.types.Operator):
### step from 0.1 to 0.9 ### step from 0.1 to 0.9
for i, l in enumerate(gpl): for i, l in enumerate(gpl):
if l.info.lower() not in ('background',): if l.name.lower() not in ('background',):
print() print()
print('>', l.info) print('>', l.name)
ns= l.info.lower().split(separator, 1)[0]#get namespace from separator ns= l.name.lower().split(separator, 1)[0]#get namespace from separator
print("namespace", ns)#Dbg print("namespace", ns)#Dbg
if context.scene.gptoolprops.autotint_namespace: if context.scene.gptoolprops.autotint_namespace:
h = get_hue_by_name(ns, hue_offset)#l.info == individuels h = get_hue_by_name(ns, hue_offset)#l.name == individuels
else: else:
h = translate_range((i + hue_offset/100)%layer_ct, 0, layer_ct, 0.1, 0.9) h = translate_range((i + hue_offset/100)%layer_ct, 0, layer_ct, 0.1, 0.9)
+20 -20
View File
@@ -25,7 +25,7 @@ if all_strokes:
l.hide = False l.hide = False
l.lock = False l.lock = False
l.lock_frame = False l.lock_frame = False
bpy.ops.object.mode_set(mode='EDIT_GPENCIL') bpy.ops.object.mode_set(mode='EDIT')
for fnum in frame_list: for fnum in frame_list:
@@ -54,7 +54,7 @@ def batch_reproject(obj, proj_type='VIEW', all_strokes=True, restore_frame=False
plan_co, plane_no = utils.get_gp_draw_plane(obj, orient=proj_type) plan_co, plane_no = utils.get_gp_draw_plane(obj, orient=proj_type)
frame_list = [f.frame_number for l in obj.data.layers for f in l.frames if len(f.strokes)] frame_list = [f.frame_number for l in obj.data.layers for f in l.frames if len(f.drawing.strokes)]
frame_list = list(set(frame_list)) frame_list = list(set(frame_list))
frame_list.sort() frame_list.sort()
@@ -78,7 +78,7 @@ def batch_reproject(obj, proj_type='VIEW', all_strokes=True, restore_frame=False
f = next((f for f in l.frames if f.frame_number == i), None) f = next((f for f in l.frames if f.frame_number == i), None)
if f is None: if f is None:
continue continue
for s in f.strokes: for s in f.drawing.strokes:
## Batch matrix apply (Here is slower than list comprehension). ## Batch matrix apply (Here is slower than list comprehension).
# nb_points = len(s.points) # nb_points = len(s.points)
# coords = np.empty(nb_points * 3, dtype='float64') # coords = np.empty(nb_points * 3, dtype='float64')
@@ -86,13 +86,13 @@ def batch_reproject(obj, proj_type='VIEW', all_strokes=True, restore_frame=False
# world_co_3d = utils.matrix_transform(coords.reshape((nb_points, 3)), matrix) # world_co_3d = utils.matrix_transform(coords.reshape((nb_points, 3)), matrix)
## list comprehension method ## list comprehension method
world_co_3d = [obj.matrix_world @ p.co for p in s.points] world_co_3d = [obj.matrix_world @ p.position for p in s.points]
new_world_co_3d = [intersect_line_plane(origin, p, plan_co, plane_no) for p in world_co_3d] new_world_co_3d = [intersect_line_plane(origin, p, plan_co, plane_no) for p in world_co_3d]
## Basic method (Slower than foreach_set) ## Basic method (Slower than foreach_set)
# for i, p in enumerate(s.points): # for i, p in enumerate(s.points):
# p.co = obj.matrix_world.inverted() @ new_world_co_3d[i] # p.position = obj.matrix_world.inverted() @ new_world_co_3d[i]
## Ravel new coordinate on the fly ## Ravel new coordinate on the fly
new_local_coords = [axis for p in new_world_co_3d for axis in matrix_inv @ p] new_local_coords = [axis for p in new_world_co_3d for axis in matrix_inv @ p]
@@ -139,9 +139,9 @@ def align_global(reproject=True, ref=None, all_strokes=True):
# world_coords = [] # world_coords = []
for l in o.data.layers: for l in o.data.layers:
for f in l.frames: for f in l.frames:
for s in f.strokes: for s in f.drawing.strokes:
## foreach ## foreach
coords = [p.co @ mat.inverted() @ new_mat for p in s.points] coords = [p.position @ mat.inverted() @ new_mat for p in s.points]
# print('coords: ', coords) # print('coords: ', coords)
# print([co for v in coords for co in v]) # print([co for v in coords for co in v])
s.points.foreach_set('co', [co for v in coords for co in v]) s.points.foreach_set('co', [co for v in coords for co in v])
@@ -152,11 +152,11 @@ def align_global(reproject=True, ref=None, all_strokes=True):
# for p in s.points: # for p in s.points:
## GOOD : ## GOOD :
# world_co = mat @ p.co # world_co = mat @ p.position
# p.co = new_mat.inverted() @ world_co # p.position = new_mat.inverted() @ world_co
## GOOD : ## GOOD :
# p.co = p.co @ mat.inverted() @ new_mat # p.position = p.position @ mat.inverted() @ new_mat
if o.parent: if o.parent:
o.matrix_world = new_mat o.matrix_world = new_mat
@@ -216,9 +216,9 @@ def align_all_frames(reproject=True, ref=None, all_strokes=True):
scale_mat = get_scale_matrix(o_scale) scale_mat = get_scale_matrix(o_scale)
new_mat = loc_mat @ rot_mat @ scale_mat new_mat = loc_mat @ rot_mat @ scale_mat
for s in f.strokes: for s in f.drawing.strokes:
## foreach ## foreach
coords = [p.co @ mat.inverted() @ new_mat for p in s.points] coords = [p.position @ mat.inverted() @ new_mat for p in s.points]
# print('coords: ', coords) # print('coords: ', coords)
# print([co for v in coords for co in v]) # print([co for v in coords for co in v])
s.points.foreach_set('co', [co for v in coords for co in v]) s.points.foreach_set('co', [co for v in coords for co in v])
@@ -267,7 +267,7 @@ class GPTB_OT_realign(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
reproject : bpy.props.BoolProperty( reproject : bpy.props.BoolProperty(
name='Reproject', default=True, name='Reproject', default=True,
@@ -283,7 +283,7 @@ class GPTB_OT_realign(bpy.types.Operator):
## add option to bake strokes if rotation anim is not constant ? might generate too many Keyframes ## add option to bake strokes if rotation anim is not constant ? might generate too many Keyframes
def invoke(self, context, event): def invoke(self, context, event):
if context.object.data.use_multiedit: if context.scene.tool_settings.use_grease_pencil_multi_frame_editing:
self.report({'ERROR'}, 'Does not work in Multiframe mode') self.report({'ERROR'}, 'Does not work in Multiframe mode')
return {"CANCELLED"} return {"CANCELLED"}
@@ -365,7 +365,7 @@ class GPTB_OT_batch_reproject_all_frames(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' return context.object and context.object.type == 'GREASEPENCIL'
all_strokes : bpy.props.BoolProperty( all_strokes : bpy.props.BoolProperty(
name='All Strokes', default=True, name='All Strokes', default=True,
@@ -383,7 +383,7 @@ class GPTB_OT_batch_reproject_all_frames(bpy.types.Operator):
default='CURRENT') default='CURRENT')
def invoke(self, context, event): def invoke(self, context, event):
if context.object.data.use_multiedit: if context.scene.tool_settings.use_grease_pencil_multi_frame_editing:
self.report({'ERROR'}, 'Does not work in Multi-edit') self.report({'ERROR'}, 'Does not work in Multi-edit')
return {"CANCELLED"} return {"CANCELLED"}
return context.window_manager.invoke_props_dialog(self) return context.window_manager.invoke_props_dialog(self)
@@ -432,12 +432,12 @@ class GPTB_OT_batch_reproject_all_frames(bpy.types.Operator):
### -- MENU ENTRY -- ### -- MENU ENTRY --
def reproject_clean_menu(self, context): def reproject_clean_menu(self, context):
if context.mode == 'EDIT_GPENCIL': if context.mode == 'EDIT_GREASE_PENCIL':
self.layout.operator_context = 'INVOKE_REGION_WIN' # needed for popup (also works with 'INVOKE_DEFAULT') self.layout.operator_context = 'INVOKE_REGION_WIN' # needed for popup (also works with 'INVOKE_DEFAULT')
self.layout.operator('gp.batch_reproject_all_frames', icon='KEYTYPE_JITTER_VEC') self.layout.operator('gp.batch_reproject_all_frames', icon='KEYTYPE_JITTER_VEC')
def reproject_context_menu(self, context): def reproject_context_menu(self, context):
if context.mode == 'EDIT_GPENCIL' and context.scene.tool_settings.gpencil_selectmode_edit == 'STROKE': if context.mode == 'EDIT_GREASE_PENCIL' and context.scene.tool_settings.gpencil_selectmode_edit == 'STROKE':
self.layout.operator_context = 'INVOKE_REGION_WIN' # needed for popup self.layout.operator_context = 'INVOKE_REGION_WIN' # needed for popup
self.layout.operator('gp.batch_reproject_all_frames', icon='KEYTYPE_JITTER_VEC') self.layout.operator('gp.batch_reproject_all_frames', icon='KEYTYPE_JITTER_VEC')
@@ -450,12 +450,12 @@ def register():
for cl in classes: for cl in classes:
bpy.utils.register_class(cl) bpy.utils.register_class(cl)
bpy.types.VIEW3D_MT_gpencil_edit_context_menu.append(reproject_context_menu) bpy.types.VIEW3D_MT_grease_pencil_edit_context_menu.append(reproject_context_menu)
bpy.types.GPENCIL_MT_cleanup.append(reproject_clean_menu) bpy.types.GPENCIL_MT_cleanup.append(reproject_clean_menu)
def unregister(): def unregister():
bpy.types.GPENCIL_MT_cleanup.remove(reproject_clean_menu) bpy.types.GPENCIL_MT_cleanup.remove(reproject_clean_menu)
bpy.types.VIEW3D_MT_gpencil_edit_context_menu.remove(reproject_context_menu) bpy.types.VIEW3D_MT_grease_pencil_edit_context_menu.remove(reproject_context_menu)
for cl in reversed(classes): for cl in reversed(classes):
bpy.utils.unregister_class(cl) bpy.utils.unregister_class(cl)
+2
View File
@@ -4,6 +4,8 @@ Blender addon - Various tool to help with grease pencil in animation productions
**[Download latest](https://git.autourdeminuit.com/autour_de_minuit/gp_toolbox/archive/master.zip)** **[Download latest](https://git.autourdeminuit.com/autour_de_minuit/gp_toolbox/archive/master.zip)**
**[Download for Blender 4.2 and below](https://git.autourdeminuit.com/autour_de_minuit/gp_toolbox/archive/v3.3.0.zip)**
**[Demo video](https://www.youtube.com/watch?v=Htgao_uPWNs)** **[Demo video](https://www.youtube.com/watch?v=Htgao_uPWNs)**
**[Readme Doc in French](README_FR.md)** **[Readme Doc in French](README_FR.md)**
+2
View File
@@ -4,6 +4,8 @@ Blender addon - Boîte à outils de grease pencil pour la production d'animation
**[Télécharger la dernière version](https://git.autourdeminuit.com/autour_de_minuit/gp_toolbox/archive/master.zip)** **[Télécharger la dernière version](https://git.autourdeminuit.com/autour_de_minuit/gp_toolbox/archive/master.zip)**
**[Télécharger pour Blender 4.2 ou inférieure](https://git.autourdeminuit.com/autour_de_minuit/gp_toolbox/archive/v3.3.0.zip)**
**[Demo video](https://www.youtube.com/watch?v=Htgao_uPWNs)** **[Demo video](https://www.youtube.com/watch?v=Htgao_uPWNs)**
**[English Readme Doc](README.md)** **[English Readme Doc](README.md)**
+1 -1
View File
@@ -7,7 +7,7 @@ from .utils import get_addon_prefs
class GPTB_WT_eraser(WorkSpaceTool): class GPTB_WT_eraser(WorkSpaceTool):
bl_space_type = 'VIEW_3D' bl_space_type = 'VIEW_3D'
bl_context_mode = 'PAINT_GPENCIL' bl_context_mode = 'PAINT_GREASE_PENCIL'
# The prefix of the idname should be your add-on name. # The prefix of the idname should be your add-on name.
bl_idname = "gp.eraser_tool" bl_idname = "gp.eraser_tool"
+23 -16
View File
@@ -20,7 +20,7 @@ class GPTB_PT_dataprop_panel(Panel):
# bl_category = "Tool" # bl_category = "Tool"
# bl_idname = "ADDONID_PT_panel_name"# identifier, if ommited, takes the name of the class. # bl_idname = "ADDONID_PT_panel_name"# identifier, if ommited, takes the name of the class.
bl_label = "Pseudo color"# title bl_label = "Pseudo color"# title
bl_parent_id = "DATA_PT_gpencil_layers"#subpanel of this ID bl_parent_id = "DATA_PT_grease_pencil_layers"#subpanel of this ID
bl_options = {'DEFAULT_CLOSED'} bl_options = {'DEFAULT_CLOSED'}
def draw(self, context): def draw(self, context):
@@ -144,7 +144,7 @@ class GPTB_PT_sidebar_panel(Panel):
col.prop(context.scene.gptoolprops, 'keyframe_type', text='Jump On') # Keyframe Jump col.prop(context.scene.gptoolprops, 'keyframe_type', text='Jump On') # Keyframe Jump
# col.prop(context.space_data.overlay, 'use_gpencil_onion_skin') # not often used # col.prop(context.space_data.overlay, 'use_gpencil_onion_skin') # not often used
if context.object and context.object.type == 'GPENCIL': if context.object and context.object.type == 'GREASEPENCIL':
# col.prop(context.object.data, 'use_autolock_layers') # not often used # col.prop(context.object.data, 'use_autolock_layers') # not often used
col.prop(context.object, 'show_in_front') # text='In Front' col.prop(context.object, 'show_in_front') # text='In Front'
@@ -191,23 +191,23 @@ class GPTB_PT_anim_manager(Panel):
# import time # import time
# t0 = time.perf_counter() # t0 = time.perf_counter()
# objs = [o for o in context.scene.objects if o.type not in ('GPENCIL', 'CAMERA')] # objs = [o for o in context.scene.objects if o.type not in ('GREASEPENCIL', 'CAMERA')]
# gps = [o for o in context.scene.objects if o.type == 'GPENCIL'] # gps = [o for o in context.scene.objects if o.type == 'GREASEPENCIL']
# cams = [o for o in context.scene.objects if o.type == 'CAMERA'] # cams = [o for o in context.scene.objects if o.type == 'CAMERA']
objs = [] objs = []
gps = [] gps = []
cams = [] cams = []
for o in context.scene.objects: for o in context.scene.objects:
if o.type not in ('GPENCIL', 'CAMERA'): if o.type not in ('GREASEPENCIL', 'CAMERA'):
objs.append(o) objs.append(o)
elif o.type == 'GPENCIL': elif o.type == 'GREASEPENCIL':
gps.append(o) gps.append(o)
elif o.type == 'CAMERA': elif o.type == 'CAMERA':
cams.append(o) cams.append(o)
# print(f'{time.perf_counter() - t0:.8f}s') # print(f'{time.perf_counter() - t0:.8f}s')
return {'OBJECT': objs, 'GPENCIL': gps, 'CAMERA': cams} return {'OBJECT': objs, 'GREASEPENCIL': gps, 'CAMERA': cams}
def draw(self, context): def draw(self, context):
@@ -221,7 +221,7 @@ class GPTB_PT_anim_manager(Panel):
col.operator('gp.list_disabled_anims') col.operator('gp.list_disabled_anims')
## Show Enable / Disable anims ## Show Enable / Disable anims
for cat, cat_type in [('Obj anims:', 'OBJECT'), ('Cam anims:', 'CAMERA'), ('Gp anims:', 'GPENCIL')]: for cat, cat_type in [('Obj anims:', 'OBJECT'), ('Cam anims:', 'CAMERA'), ('Gp anims:', 'GREASEPENCIL')]:
on_icon, off_icon = anim_status(obj_types[cat_type]) on_icon, off_icon = anim_status(obj_types[cat_type])
subcol = col.column() subcol = col.column()
@@ -242,7 +242,7 @@ class GPTB_PT_anim_manager(Panel):
row = subcol.row(align=True) row = subcol.row(align=True)
row.label(text='Gp modifiers:') row.label(text='Gp modifiers:')
on_icon, off_icon = gp_modifier_status(obj_types['GPENCIL']) on_icon, off_icon = gp_modifier_status(obj_types['GREASEPENCIL'])
# subcol.alert = off_icon == 'LAYER_ACTIVE' # Turn red # subcol.alert = off_icon == 'LAYER_ACTIVE' # Turn red
row.operator('gp.toggle_hide_gp_modifier', text='ON', icon=on_icon).show = True row.operator('gp.toggle_hide_gp_modifier', text='ON', icon=on_icon).show = True
row.operator('gp.toggle_hide_gp_modifier', text='OFF', icon=off_icon).show = False row.operator('gp.toggle_hide_gp_modifier', text='OFF', icon=off_icon).show = False
@@ -279,8 +279,7 @@ class GPTB_PT_anim_manager(Panel):
col.use_property_split = False col.use_property_split = False
text, icon = ('Cursor Follow On', 'PIVOT_CURSOR') if context.scene.gptoolprops.cursor_follow else ('Cursor Follow Off', 'CURSOR') text, icon = ('Cursor Follow On', 'PIVOT_CURSOR') if context.scene.gptoolprops.cursor_follow else ('Cursor Follow Off', 'CURSOR')
col.prop(context.scene.gptoolprops, 'cursor_follow', text=text, icon=icon) col.prop(context.scene.gptoolprops, 'cursor_follow', text=text, icon=icon)
if context.scene.gptoolprops.cursor_follow:
col.prop(context.scene.gptoolprops, 'cursor_follow_target', text='Target', icon='OBJECT_DATA')
class GPTB_PT_toolbox_playblast(Panel): class GPTB_PT_toolbox_playblast(Panel):
bl_label = "Playblast" bl_label = "Playblast"
@@ -426,7 +425,7 @@ def palette_manager_menu(self, context):
"""Palette menu to append in existing menu""" """Palette menu to append in existing menu"""
# GPENCIL_MT_material_context_menu # GPENCIL_MT_material_context_menu
layout = self.layout layout = self.layout
# {'EDIT_GPENCIL', 'PAINT_GPENCIL','SCULPT_GPENCIL','WEIGHT_GPENCIL', 'VERTEX_GPENCIL'} # {'EDIT_GREASE_PENCIL', 'PAINT_GREASE_PENCIL','SCULPT_GREASE_PENCIL','WEIGHT_GREASE_PENCIL', 'VERTEX_GPENCIL'}
layout.separator() layout.separator()
prefs = get_addon_prefs() prefs = get_addon_prefs()
@@ -659,7 +658,7 @@ class GPTB_PT_tools_grease_pencil_interpolate(Panel):
# settings = context.tool_settings.gpencil_interpolate # old 2.92 global settings # settings = context.tool_settings.gpencil_interpolate # old 2.92 global settings
## access active tool settings ## access active tool settings
# settings = context.workspace.tools[0].operator_properties('gpencil.interpolate') # settings = context.workspace.tools[0].operator_properties('gpencil.interpolate')
settings = context.workspace.tools.from_space_view3d_mode('PAINT_GPENCIL').operator_properties('gpencil.interpolate') settings = context.workspace.tools.from_space_view3d_mode('PAINT_GREASE_PENCIL').operator_properties('gpencil.interpolate')
## custom curve access (still in gp interpolate tools) ## custom curve access (still in gp interpolate tools)
interpolate_settings = context.tool_settings.gpencil_interpolate interpolate_settings = context.tool_settings.gpencil_interpolate
@@ -735,7 +734,7 @@ def interpolate_header_ui(self, context):
layout = self.layout layout = self.layout
obj = context.active_object obj = context.active_object
if obj and obj.type == 'GPENCIL' and context.gpencil_data: if obj and obj.type == 'GREASEPENCIL' and context.gpencil_data:
gpd = context.gpencil_data gpd = context.gpencil_data
else: else:
return return
@@ -769,7 +768,10 @@ def register():
for cls in classes: for cls in classes:
bpy.utils.register_class(cls) bpy.utils.register_class(cls)
bpy.types.GPENCIL_MT_material_context_menu.append(palette_manager_menu) bpy.types.GPENCIL_MT_material_context_menu.append(palette_manager_menu)
bpy.types.DOPESHEET_PT_gpencil_layer_display.append(expose_use_channel_color_pref) bpy.types.DOPESHEET_PT_grease_pencil_mode.append(expose_use_channel_color_pref)
# bpy.types.GPENCIL_MT_material_context_menu.append(palette_manager_menu)
# bpy.types.DOPESHEET_PT_gpencil_layer_display.append(expose_use_channel_color_pref)
# bpy.types.VIEW3D_HT_header.append(interpolate_header_ui) # WIP # bpy.types.VIEW3D_HT_header.append(interpolate_header_ui) # WIP
# if bpy.app.version >= (3,0,0): # if bpy.app.version >= (3,0,0):
@@ -778,8 +780,13 @@ def register():
def unregister(): def unregister():
# bpy.types.VIEW3D_HT_header.remove(interpolate_header_ui) # WIP # bpy.types.VIEW3D_HT_header.remove(interpolate_header_ui) # WIP
bpy.types.DOPESHEET_PT_gpencil_layer_display.remove(expose_use_channel_color_pref)
bpy.types.DOPESHEET_PT_grease_pencil_mode.remove(expose_use_channel_color_pref)
bpy.types.GPENCIL_MT_material_context_menu.remove(palette_manager_menu) bpy.types.GPENCIL_MT_material_context_menu.remove(palette_manager_menu)
# bpy.types.DOPESHEET_PT_gpencil_layer_display.remove(expose_use_channel_color_pref)
# bpy.types.GPENCIL_MT_material_context_menu.remove(palette_manager_menu)
# if bpy.app.version >= (3,0,0): # if bpy.app.version >= (3,0,0):
# bpy.types.ASSETBROWSER_PT_metadata.remove(asset_browser_ui) # bpy.types.ASSETBROWSER_PT_metadata.remove(asset_browser_ui)
+5 -12
View File
@@ -4,8 +4,8 @@ bl_info = {
"name": "GP toolbox", "name": "GP toolbox",
"description": "Tool set for Grease Pencil in animation production", "description": "Tool set for Grease Pencil in animation production",
"author": "Samuel Bernou, Christophe Seux", "author": "Samuel Bernou, Christophe Seux",
"version": (3, 3, 5), "version": (4, 0, 0),
"blender": (4, 0, 0), "blender": (4, 3, 0),
"location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties", "location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
"warning": "", "warning": "",
"doc_url": "https://git.autourdeminuit.com/autour_de_minuit/gp_toolbox", "doc_url": "https://git.autourdeminuit.com/autour_de_minuit/gp_toolbox",
@@ -625,8 +625,9 @@ class GPTB_prefs(bpy.types.AddonPreferences):
layout.label(text='Following checks will be made when clicking "Check File" button:') layout.label(text='Following checks will be made when clicking "Check File" button:')
col = layout.column() col = layout.column()
col.use_property_split = True col.use_property_split = True
col.label(text='The popup list possible fixes, you can then use "Apply Fixes"', icon='INFO') col.prop(self.fixprops, 'check_only')
# col.label(text='(preferences for tool changes are directly applied)', icon='BLANK1') col.label(text='If dry run is checked, no modification is done', icon='INFO')
col.label(text='Use Ctrl + Click on "Check File" button to invert the behavior', icon='BLANK1')
col.separator() col.separator()
col.prop(self.fixprops, 'lock_main_cam') col.prop(self.fixprops, 'lock_main_cam')
col.prop(self.fixprops, 'set_scene_res', text=f'Reset Scene Resolution (to {self.render_res_x}x{self.render_res_y})') col.prop(self.fixprops, 'set_scene_res', text=f'Reset Scene Resolution (to {self.render_res_x}x{self.render_res_y})')
@@ -812,10 +813,6 @@ addon_modules = (
) )
def register(): def register():
if bpy.app.version >= (4, 3, 0):
print(f"Skip GP toolbox load, version {'.'.join([str(x) for x in bl_info['version']])} incompatible with Blender 4.3+")
return
# Register property group first # Register property group first
properties.register() properties.register()
for cls in classes: for cls in classes:
@@ -841,10 +838,6 @@ def register():
def unregister(): def unregister():
if bpy.app.version >= (4, 3, 0):
# print(f'GP Toolbox version is not compatible with Blender 4.3+')
return
if 'remap_relative' in [hand.__name__ for hand in bpy.app.handlers.save_pre]: if 'remap_relative' in [hand.__name__ for hand in bpy.app.handlers.save_pre]:
bpy.app.handlers.save_pre.remove(remap_relative) bpy.app.handlers.save_pre.remove(remap_relative)
+1 -1
View File
@@ -99,7 +99,7 @@ def gp_stroke_angle_split (frame, strokes, angle):
splitted_loops = bm_angle_split(bm,angle) splitted_loops = bm_angle_split(bm,angle)
frame.strokes.remove(stroke_info['stroke']) frame.drawing.strokes.remove(stroke_info['stroke'])
for loop in splitted_loops : for loop in splitted_loops :
loop_info = [{'co':v.co,'strength': v[strength], 'pressure' :v[pressure],'select':v[select]} for v in loop] loop_info = [{'co':v.co,'strength': v[strength], 'pressure' :v[pressure],'select':v[select]} for v in loop]
new_stroke = draw_gp_stroke(loop_info,frame,palette,width = line_width) new_stroke = draw_gp_stroke(loop_info,frame,palette,width = line_width)
+7 -7
View File
@@ -21,16 +21,21 @@ def update_layer_name(self, context):
if not self.layer_name: if not self.layer_name:
# never replace by nothing (since there should be prefix/suffix) # never replace by nothing (since there should be prefix/suffix)
return return
if not context.object or context.object.type != 'GPENCIL': if not context.object or context.object.type != 'GREASEPENCIL':
return return
if not context.object.data.layers.active: if not context.object.data.layers.active:
return return
layer_name_build(context.object.data.layers.active, desc=self.layer_name) layer_name_build(context.object.data.layers.active, desc=self.layer_name)
# context.object.data.layers.active.info = self.layer_name # context.object.data.layers.active.name = self.layer_name
class GP_PG_FixSettings(PropertyGroup): class GP_PG_FixSettings(PropertyGroup):
check_only : BoolProperty(
name="Dry run mode (Check only)",
description="Do not change anything, just print the messages",
default=False, options={'HIDDEN'})
lock_main_cam : BoolProperty( lock_main_cam : BoolProperty(
name="Lock Main Cam", name="Lock Main Cam",
description="Lock the main camera (works only if 'layout' is not in name)", description="Lock the main camera (works only if 'layout' is not in name)",
@@ -177,11 +182,6 @@ class GP_PG_ToolsSettings(PropertyGroup):
name='Cursor Follow', description="3D cursor follow active object animation when activated", name='Cursor Follow', description="3D cursor follow active object animation when activated",
default=False, update=cursor_follow_update) default=False, update=cursor_follow_update)
cursor_follow_target : bpy.props.PointerProperty(
name='Cursor Follow Target',
description="Optional target object to follow for cursor instead of active object",
type=bpy.types.Object, update=cursor_follow_update)
edit_lines_opacity : FloatProperty( edit_lines_opacity : FloatProperty(
name="Edit Lines Opacity", description="Change edit lines opacity for all grease pencils", name="Edit Lines Opacity", description="Change edit lines opacity for all grease pencils",
default=0.5, min=0.0, max=1.0, step=3, precision=2, update=change_edit_lines_opacity) default=0.5, min=0.0, max=1.0, step=3, precision=2, update=change_edit_lines_opacity)
+39 -48
View File
@@ -29,9 +29,9 @@ def get_matrix(ob) :
return ob.matrix_world.copy() return ob.matrix_world.copy()
def set_matrix(gp_frame,mat): def set_matrix(gp_frame,mat):
for stroke in gp_frame.strokes : for stroke in gp_frame.drawing.strokes :
for point in stroke.points : for point in stroke.points :
point.co = mat @ point.co point.position = mat @ point.position
# get view vector location (the 2 methods work fine) # get view vector location (the 2 methods work fine)
def get_view_origin_position(): def get_view_origin_position():
@@ -160,7 +160,7 @@ def simple_draw_gp_stroke(pts, frame, width = 2, mat_id = 0):
draw basic stroke by passing list of point 3D coordinate draw basic stroke by passing list of point 3D coordinate
the frame to draw on and optional width parameter (default = 2) the frame to draw on and optional width parameter (default = 2)
''' '''
stroke = frame.strokes.new() stroke = frame.drawing.strokes.new()
stroke.line_width = width stroke.line_width = width
stroke.display_mode = '3DSPACE' stroke.display_mode = '3DSPACE'
stroke.material_index = mat_id stroke.material_index = mat_id
@@ -173,12 +173,12 @@ def simple_draw_gp_stroke(pts, frame, width = 2, mat_id = 0):
# for i, pt in enumerate(pts): # for i, pt in enumerate(pts):
# stroke.points.add() # stroke.points.add()
# dest_point = stroke.points[i] # dest_point = stroke.points[i]
# dest_point.co = pt # dest_point.position = pt
return stroke return stroke
## OLD - need update ## OLD - need update
def draw_gp_stroke(loop_info, frame, palette, width = 2) : def draw_gp_stroke(loop_info, frame, palette, width = 2) :
stroke = frame.strokes.new(palette) stroke = frame.drawing.strokes.new(palette)
stroke.line_width = width stroke.line_width = width
stroke.display_mode = '3DSPACE'# old -> draw_mode stroke.display_mode = '3DSPACE'# old -> draw_mode
@@ -372,24 +372,24 @@ def create_gp_palette(gp_data_block,info) :
def get_gp_objects(selection=True): def get_gp_objects(selection=True):
'''return selected objects or only the active one''' '''return selected objects or only the active one'''
if not bpy.context.active_object or bpy.context.active_object.type != 'GPENCIL': if not bpy.context.active_object or bpy.context.active_object.type != 'GREASEPENCIL':
print('No active GP object') print('No active GP object')
return [] return []
active = bpy.context.active_object active = bpy.context.active_object
if selection: if selection:
selection = [o for o in bpy.context.selected_objects if o.type == 'GPENCIL'] selection = [o for o in bpy.context.selected_objects if o.type == 'GREASEPENCIL']
if not active in selection: if not active in selection:
selection += [active] selection += [active]
return selection return selection
if bpy.context.active_object and bpy.context.active_object.type == 'GPENCIL': if bpy.context.active_object and bpy.context.active_object.type == 'GREASEPENCIL':
return [active] return [active]
return [] return []
def get_gp_datas(selection=True): def get_gp_datas(selection=True):
'''return selected objects or only the active one''' '''return selected objects or only the active one'''
if not bpy.context.active_object or bpy.context.active_object.type != 'GPENCIL': if not bpy.context.active_object or bpy.context.active_object.type != 'GREASEPENCIL':
print('No active GP object') print('No active GP object')
return [] return []
@@ -397,15 +397,15 @@ def get_gp_datas(selection=True):
if selection: if selection:
selected = [] selected = []
for o in bpy.context.selected_objects: for o in bpy.context.selected_objects:
if o.type == 'GPENCIL': if o.type == 'GREASEPENCIL':
if o.data not in selected: if o.data not in selected:
selected.append(o.data) selected.append(o.data)
# selected = [o.data for o in bpy.context.selected_objects if o.type == 'GPENCIL'] # selected = [o.data for o in bpy.context.selected_objects if o.type == 'GREASEPENCIL']
if not active_data in selected: if not active_data in selected:
selected += [active_data] selected += [active_data]
return selected return selected
if bpy.context.active_object and bpy.context.active_object.type == 'GPENCIL': if bpy.context.active_object and bpy.context.active_object.type == 'GREASEPENCIL':
return [active_data] return [active_data]
print('EOL. No active GP object') print('EOL. No active GP object')
@@ -440,7 +440,7 @@ def get_active_frame(layer_name=None):
if layer_name: if layer_name:
lay = bpy.context.scene.grease_pencil.layers.get(layer_name) lay = bpy.context.scene.grease_pencil.layers.get(layer_name)
if lay: if lay:
frame = lay.active_frame frame = lay.current_frame()
if frame: if frame:
return frame return frame
else: else:
@@ -449,7 +449,7 @@ def get_active_frame(layer_name=None):
print('no layers named', layer_name, 'in scene layers') print('no layers named', layer_name, 'in scene layers')
else:#active layer else:#active layer
frame = bpy.context.scene.grease_pencil.layers.active.active_frame frame = bpy.context.scene.grease_pencil.layers.active.current_frame()
if frame: if frame:
return frame return frame
else: else:
@@ -457,7 +457,7 @@ def get_active_frame(layer_name=None):
def get_stroke_2D_coords(stroke): def get_stroke_2D_coords(stroke):
'''return a list containing points 2D coordinates of passed gp stroke object''' '''return a list containing points 2D coordinates of passed gp stroke object'''
return [location_to_region(p.co) for p in stroke.points] return [location_to_region(p.position) for p in stroke.points]
'''#foreach method for retreiving multiple other attribute quickly and stack them '''#foreach method for retreiving multiple other attribute quickly and stack them
point_nb = len(stroke.points) point_nb = len(stroke.points)
@@ -472,14 +472,14 @@ def get_stroke_2D_coords(stroke):
def get_all_stroke_2D_coords(frame): def get_all_stroke_2D_coords(frame):
'''return a list of lists with all strokes's points 2D location''' '''return a list of lists with all strokes's points 2D location'''
## using modification from get_stroke_2D_coords func' ## using modification from get_stroke_2D_coords func'
return [get_stroke_2D_coords(s) for s in frame.strokes] return [get_stroke_2D_coords(s) for s in frame.drawing.strokes]
## direct ## direct
#return[[location_to_region(p.co) for p in s.points] for s in frame.strokes] #return[[location_to_region(p.position) for p in s.points] for s in frame.drawing.strokes]
def selected_strokes(frame): def selected_strokes(frame):
'''return all stroke having a point selected as a list of strokes objects''' '''return all stroke having a point selected as a list of strokes objects'''
stlist = [] stlist = []
for i, s in enumerate(frame.strokes): for i, s in enumerate(frame.drawing.strokes):
if any(pt.select for pt in s.points): if any(pt.select for pt in s.points):
stlist.append(s) stlist.append(s)
return stlist return stlist
@@ -491,7 +491,7 @@ def copy_stroke_to_frame(s, frame, select=True):
return created stroke return created stroke
''' '''
ns = frame.strokes.new() ns = frame.drawing.strokes.new()
## Set strokes attr ## Set strokes attr
stroke_attr = [ stroke_attr = [
@@ -823,37 +823,28 @@ def convert_attr(Attr):
def show_message_box(_message = "", _title = "Message Box", _icon = 'INFO'): def show_message_box(_message = "", _title = "Message Box", _icon = 'INFO'):
'''Show message box with element passed as string or list '''Show message box with element passed as string or list
if _message if a list of lists: if _message if a list of lists:
if first element is "OPERATOR":
List format: ["OPERATOR", operator_id, text, icon, {prop_name: value, ...}]
if sublist have 2 element: if sublist have 2 element:
considered a label [text, icon] considered a label [text,icon]
if sublist have 3 element: if sublist have 3 element:
considered as an operator [ops_id_name, text, icon] considered as an operator [ops_id_name, text, icon]
if sublist have 4 element:
considered as a property [object, propname, text, icon]
''' '''
def draw(self, context): def draw(self, context):
layout = self.layout
for l in _message: for l in _message:
if isinstance(l, str): if isinstance(l, str):
layout.label(text=l) self.layout.label(text=l)
elif l[0] == "OPERATOR": # Special operator case with properties else:
layout.operator_context = "INVOKE_DEFAULT" if len(l) == 2: # label with icon
op = layout.operator(l[1], text=l[2], icon=l[3], emboss=False) self.layout.label(text=l[0], icon=l[1])
if len(l) > 4 and isinstance(l[4], dict): elif len(l) == 3: # ops
for prop_name, value in l[4].items(): self.layout.operator_context = "INVOKE_DEFAULT"
setattr(op, prop_name, value) self.layout.operator(l[0], text=l[1], icon=l[2], emboss=False) # <- highligh the entry
## offset pnale when using row...
# row = self.layout.row()
# row.label(text=l[1])
# row.operator(l[0], icon=l[2])
elif len(l) == 2: # label with icon
layout.label(text=l[0], icon=l[1])
elif len(l) == 3: # ops
layout.operator_context = "INVOKE_DEFAULT"
layout.operator(l[0], text=l[1], icon=l[2], emboss=False) # <- highligh the entry
elif len(l) == 4: # prop
row = layout.row(align=True)
row.label(text=l[2], icon=l[3])
row.prop(l[0], l[1], text='')
if isinstance(_message, str): if isinstance(_message, str):
_message = [_message] _message = [_message]
bpy.context.window_manager.popup_menu(draw, title = _title, icon = _icon) bpy.context.window_manager.popup_menu(draw, title = _title, icon = _icon)
@@ -1215,7 +1206,7 @@ def all_anim_enabled(objects) -> bool:
if fcu.mute: if fcu.mute:
return False return False
if o.type in ('GPENCIL', 'CAMERA'): if o.type in ('GREASEPENCIL', 'CAMERA'):
if o.data.animation_data and o.data.animation_data.action: if o.data.animation_data and o.data.animation_data.action:
## Check if object data attributes fcurves are muted ## Check if object data attributes fcurves are muted
for fcu in o.animation_data.action.fcurves: for fcu in o.animation_data.action.fcurves:
@@ -1228,9 +1219,9 @@ def all_anim_enabled(objects) -> bool:
def all_object_modifier_enabled(objects) -> bool: def all_object_modifier_enabled(objects) -> bool:
'''Return False if one modifier of one object has GP modifier disabled in viewport but enabled in render''' '''Return False if one modifier of one object has GP modifier disabled in viewport but enabled in render'''
for o in objects: for o in objects:
if o.type != 'GPENCIL': if o.type != 'GREASEPENCIL':
continue continue
for m in o.grease_pencil_modifiers: for m in o.modifier:
if m.show_render and not m.show_viewport: if m.show_render and not m.show_viewport:
return False return False
@@ -1256,7 +1247,7 @@ def has_fully_enabled_anim(o):
if fcu.mute: if fcu.mute:
return False return False
if o.type in ('GPENCIL', 'CAMERA'): if o.type in ('GREASEPENCIL', 'CAMERA'):
if o.data.animation_data and o.data.animation_data.action: if o.data.animation_data and o.data.animation_data.action:
## Check if object data attributes fcurves are muted ## Check if object data attributes fcurves are muted
for fcu in o.animation_data.action.fcurves: for fcu in o.animation_data.action.fcurves:
@@ -1301,7 +1292,7 @@ def anim_status(objects) -> tuple((str, str)):
on_count += 1 on_count += 1
count += 1 count += 1
if o.type in ('GPENCIL', 'CAMERA'): if o.type in ('GREASEPENCIL', 'CAMERA'):
datablock = o.data datablock = o.data
if datablock.animation_data is None: if datablock.animation_data is None:
continue continue
@@ -1329,12 +1320,12 @@ def gp_modifier_status(objects) -> tuple((str, str)):
'''return icons on/off tuple''' '''return icons on/off tuple'''
on_count = off_count = count = 0 on_count = off_count = count = 0
for o in objects: for o in objects:
if o.type != 'GPENCIL': if o.type != 'GREASEPENCIL':
continue continue
## Skip hided object ## Skip hided object
if o.hide_get() and o.hide_render: if o.hide_get() and o.hide_render:
continue continue
for m in o.grease_pencil_modifiers: for m in o.modifier:
if m.show_render and not m.show_viewport: if m.show_render and not m.show_viewport:
off_count += 1 off_count += 1
else: else: