From b23f15603088f2e382ce9a53093b58debc3d70e6 Mon Sep 17 00:00:00 2001
From: "Spivak Vladimir (cwolf3d)" <cwolf3d@gmail.com>
Date: Sat, 4 May 2019 17:54:56 +0300
Subject: [PATCH] LoopTools: Gstretch fix. Grease pencil must have name
 'GPencil'. Script take only the first strokes.

---
 mesh_looptools.py | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/mesh_looptools.py b/mesh_looptools.py
index ef472964b..d9348670b 100644
--- a/mesh_looptools.py
+++ b/mesh_looptools.py
@@ -61,7 +61,7 @@ looptools_cache = {}
 
 
 def get_grease_pencil(object, context):
-    gp = bpy.data.grease_pencils
+    gp = bpy.context.scene.objects['GPencil']
     if not gp:
         gp = context.view_layers.grease_pencils
     return gp
@@ -2843,13 +2843,13 @@ def gstretch_get_strokes(object, context):
     gp = get_grease_pencil(object, context)
     if not gp:
         return(None)
-    layer = context.active_gpencil_layer
+    layer = gp.data.layers[0]
     if not layer:
         return(None)
-    frame = context.active_gpencil_frame
+    frame = layer.frames[0]
     if not frame:
         return(None)
-    strokes = context.editable_gpencil_strokes
+    strokes = frame.strokes
     if len(strokes) < 1:
         return(None)
 
@@ -3828,8 +3828,15 @@ class RemoveGP(Operator):
 
     def execute(self, context):
 
-        if context.gpencil_data is not None:
-            bpy.ops.gpencil.data_unlink()
+        gp = bpy.context.scene.objects['GPencil']
+        if len(gp.data.layers[0].frames) is not 0:
+            bpy.ops.object.mode_set(mode='OBJECT')
+            bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT')
+            gp.select_set(True)
+            bpy.context.view_layer.objects.active = gp
+            bpy.ops.object.mode_set(mode='PAINT_GPENCIL')
+            bpy.ops.gpencil.active_frame_delete('INVOKE_REGION_WIN')
+            bpy.ops.object.mode_set(mode='OBJECT')
         else:
             self.report({'INFO'}, "No Grease Pencil data to Unlink")
             return {'CANCELLED'}
-- 
GitLab