GPencil Tools: Fix box-deform with multi-user data

Box deforming a grease pencil that has multiple instances now works without throwing an error.
This commit is contained in:
Samuel Bernou 2021-04-14 23:31:00 +02:00
parent 1dbdb95ed9
commit fd6407c23f
2 changed files with 15 additions and 1 deletions

View File

@ -21,7 +21,7 @@ bl_info = {
"name": "Grease Pencil Tools",
"description": "Extra tools for Grease Pencil",
"author": "Samuel Bernou, Antonio Vazquez, Daniel Martinez Lara, Matias Mendiola",
"version": (1, 4, 2),
"version": (1, 4, 3),
"blender": (2, 91, 0),
"location": "Sidebar > Grease Pencil > Grease Pencil Tools",
"warning": "",

View File

@ -262,8 +262,22 @@ def delete_cage(cage):
def apply_cage(gp_obj, cage):
mod = gp_obj.grease_pencil_modifiers.get('tmp_lattice')
multi_user = None
if mod:
if gp_obj.data.users > 1:
old = gp_obj.data
multi_user = old.name
other_user = [o for o in bpy.data.objects if o is not gp_obj and o.data is old]
gp_obj.data = gp_obj.data.copy()
bpy.ops.object.gpencil_modifier_apply(apply_as='DATA', modifier=mod.name)
if multi_user:
for o in other_user: # relink
o.data = gp_obj.data
bpy.data.grease_pencils.remove(old)
gp_obj.data.name = multi_user
else:
print('tmp_lattice modifier not found to apply...')