From b525cda28ea5c3fc419e9fc09de053ab638758b8 Mon Sep 17 00:00:00 2001 From: pullusb Date: Thu, 14 Nov 2024 16:18:56 +0100 Subject: [PATCH] gpv3 : pick closest layer from stroke --- OP_layer_picker.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/OP_layer_picker.py b/OP_layer_picker.py index 97f8bb3..fe7fa36 100644 --- a/OP_layer_picker.py +++ b/OP_layer_picker.py @@ -33,8 +33,8 @@ class GP_OT_pick_closest_layer(Operator): mouse_vec3 = Vector((*self.init_mouse, 0)) co, index, _dist = kd.find(mouse_vec3) - lid = self.point_pair[index][1] - return lid + layer = self.point_pair[index][1] + return layer def invoke(self, context, event): self.t0 = time() @@ -75,10 +75,10 @@ class GP_OT_pick_closest_layer(Operator): self.inv_mat = self.ob.matrix_world.inverted() self.point_pair = [] if context.scene.tool_settings.use_grease_pencil_multi_frame_editing: - for layer_id, l in enumerate(gp.layers): - if l.hide: # l.lock or + for layer in gp.layers: + if layer.hide: continue - for f in l.frames: + for f in layer.frames: if not f.select: continue for s in f.drawing.strokes: @@ -86,33 +86,33 @@ class GP_OT_pick_closest_layer(Operator): continue elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill: continue - self.point_pair += [(Vector((*location_to_region(mat @ p.position), 0)), layer_id) for p in s.points] + self.point_pair += [(Vector((*location_to_region(mat @ p.position), 0)), layer) for p in s.points] else: # [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): - if l.hide or not l.current_frame(): # l.lock or + for layer in gp.layers: + if layer.hide or not layer.current_frame(): continue - for s in l.current_frame().drawing.strokes: + for s in layer.current_frame().drawing.strokes: if self.stroke_filter == 'STROKE' and not self.ob.data.materials[s.material_index].grease_pencil.show_stroke: continue elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill: continue - self.point_pair += [(Vector((*location_to_region(mat @ p.position), 0)), layer_id) for p in s.points] + self.point_pair += [(Vector((*location_to_region(mat @ p.position), 0)), layer) for p in s.points] if not self.point_pair: self.report({'ERROR'}, 'No stroke found, maybe layers are locked or hidden') return {'CANCELLED'} - lid = self.filter_stroke(context) - if isinstance(lid, str): - self.report({'ERROR'}, lid) + layer_target = self.filter_stroke(context) + if isinstance(layer_target, str): + self.report({'ERROR'}, layer_target) return {'CANCELLED'} del self.point_pair # auto garbage collected ? - self.ob.data.layers.active_index = lid + self.ob.data.layers.active = layer_target ## debug show trigger time # print(f'Trigger time {time() - self.t0:.3f}')