Skip to content

Commit 2b1c19e

Browse files
committed
Fix mask layer ordering and add shallow copy of modifiers
1 parent ffd4b6c commit 2b1c19e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

Mask.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,17 +1676,12 @@ def execute(self, context):
16761676

16771677
return {'FINISHED'}
16781678

1679-
# Copy each modifier from the source - copies references and links modifiers - not working
1680-
def copy_mask_modifiers(layer, source_mask, target_mask):
1681-
for mod in source_mask.modifiers:
1682-
new_mod = target_mask.modifiers.add()
1683-
for attr in dir(mod):
1684-
if attr.startswith("_") or callable(getattr(mod, attr)):
1685-
continue
1686-
try:
1687-
setattr(new_mod, attr, getattr(mod, attr))
1688-
except Exception:
1689-
pass
1679+
def copy_mask_modifiers(layer, source_mask, target_mask):
1680+
tree = get_tree(layer)
1681+
target_mask.modifiers.clear()
1682+
1683+
for src_mod in source_mask.modifiers:
1684+
new_mod = MaskModifier.add_new_mask_modifier(target_mask, src_mod.type)
16901685

16911686
class YDuplicateLayerMask(bpy.types.Operator):
16921687
bl_idname = "wm.y_duplicate_layer_mask"
@@ -1731,6 +1726,9 @@ def execute(self, context):
17311726
ao_distance=mask.ao_distance
17321727
)
17331728

1729+
# Move under original mask
1730+
layer.masks.move(len(layer.masks) - 1, list(layer.masks).index(mask) + 1)
1731+
17341732
# Copy extra float/vector properties
17351733
new_mask.intensity_value = mask.intensity_value
17361734

@@ -1754,7 +1752,7 @@ def execute(self, context):
17541752
if i < len(new_mask.channels):
17551753
new_mask.channels[i].enable = ch.enable
17561754

1757-
#copy_mask_modifiers(layer, mask, new_mask)
1755+
copy_mask_modifiers(layer, mask, new_mask)
17581756

17591757
#self.report({'INFO'}, f"ucupaint addon: Duplicated mask '{mask.name}' as '{new_mask.name}'")
17601758
return {'FINISHED'}

0 commit comments

Comments
 (0)