Auto pick mesh collection

master
christophe.seux 2025-01-31 16:01:05 +01:00
parent 0d8ab41c57
commit 672b613bbf
2 changed files with 34 additions and 2 deletions

View File

@ -1,5 +1,7 @@
import bpy
from time import time
import re
import bpy
from mathutils import Vector
from mathutils.geometry import (barycentric_transform,
@ -15,6 +17,32 @@ from ..utils import (plane_on_bone,
following_keys)
class GP_OT_pick_collection(bpy.types.Operator):
bl_idname = "gp.pick_collection"
bl_label = "Auto Pick Mesh Collection"
#bl_description = 'Pick Mesh Collection'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.active_object and context.object.type == 'GPENCIL'
def execute(self, context):
parts = re.split(r'(-|_)', context.object.name)
for col in context.scene.collection.children_recursive:
for i in range(len(parts), -1, -1):
base = ''.join(parts[:i])
tgt_name = f'{base}_mesh'
if tgt_name == col.name:
print(f'Automatic set "{tgt_name}"')
context.scene.gp_interpo_settings.target_collection = col
return {"FINISHED"}
self.report({"WARNING"}, 'No Collection found')
return {"CANCELLED"}
class GP_OT_interpolate_stroke_base(bpy.types.Operator):
bl_idname = "gp.interpolate_stroke_base"
bl_label = "Interpolate Stroke"
@ -482,6 +510,7 @@ class GP_OT_interpolate_stroke(GP_OT_interpolate_stroke_base):
classes = (
GP_OT_interpolate_stroke_base,
GP_OT_interpolate_stroke,
GP_OT_pick_collection
)
def register():

5
ui.py
View File

@ -73,7 +73,10 @@ class GP_PT_interpolate(bpy.types.Panel):
col.prop(settings, 'smooth_level', text='Smooth')
elif settings.method == 'VELOCITY':
col.prop(settings, 'target_collection', text='Collection')
row = col.row(align=True)
row.prop(settings, 'target_collection', text='Collection')
row.operator("gp.pick_collection", text='', icon="EYEDROPPER")
col.prop(settings, 'target_object', text='Object')
col.prop(settings, 'smooth_level', text='Smooth')