-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin_OrderLayers.py
43 lines (41 loc) · 1.23 KB
/
Plugin_OrderLayers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
from gimpfu import *
import re
nameLayers=[]
def orderLayers(image, drawable,bInverse):
if drawable:
parent = pdb.gimp_item_get_parent(drawable)
if not parent:
parent=image
pdb.gimp_image_undo_group_start(image)
for layer in parent.layers:
nameLayers.append(layer.name)
if parent==image:
parent = None
for namelayer in natural_sort(nameLayers,not bInverse):
item = pdb.gimp_image_get_layer_by_name(image, namelayer)
pdb.gimp_image_reorder_item(image, item, parent, 0)
pdb.gimp_image_undo_group_end(image)
def natural_sort(l,Reverse=False):
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
return sorted(l, key = alphanum_key, reverse=Reverse)
register(
"python_fu_OrderLayers",
"Sort the layers",
"Nothing a",
"Anonymous a",
"1.1.0",
"2020",
"Order Layers...",
"*",
[
(PF_IMAGE,"image","Input image", None),
(PF_DRAWABLE,"drawable", "Input drawable", None),
(PF_TOGGLE, "bInverse", "Reverse", False),
],
[],
orderLayers,
menu="<Image>/Layer/Tools/"
)
main()