-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin_ParentGroupForLayers.py
65 lines (61 loc) · 2.26 KB
/
Plugin_ParentGroupForLayers.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
from gimpfu import *
import gimpfu
import re
import subprocess
import inspect
import sys
import os
def ParentLayerGroup(img, Drawable,sPrefix,bRemove,sSufix,iOrderGroup,bRoot):
def childrenreOrder(g):
for layer in g.layers:
if (type(layer) == gimp.GroupLayer):
childrenreOrder(layer)
else:
pdb.gimp_image_reorder_item(img,layer,None,0)
iOrderGroup=int(iOrderGroup)
pdb.gimp_image_undo_group_start(img)
if bRoot==True:
childrenreOrder(img)
else:
NoLayers, IDLayers = pdb.gimp_image_get_layers(img)
for IDLayer in IDLayers:
Layer = gimp._id2drawable(IDLayer)
if pdb.gimp_item_is_group(Layer) == False:
if bRemove:
NameGroup = re.sub(sSufix, "", Layer.name)
else:
NameGroup = Layer.name
layerGroup = pdb.gimp_image_get_layer_by_name(img, sPrefix + NameGroup)
if layerGroup is None:
layerGroup = pdb.gimp_layer_group_new(img)
layerGroup.name = sPrefix + NameGroup
img.add_layer(layerGroup,iOrderGroup)
if iOrderGroup>=0:
pdb.gimp_image_reorder_item(img,Layer,layerGroup,iOrderGroup)
else:
pdb.gimp_image_reorder_item(img,Layer,layerGroup,len(layerGroup.layers)+iOrderGroup+1)
pdb.gimp_image_undo_group_end(img)
register(
"python_fu_ParentGroupLayer",
"It allows to group the images that are in the root within a group",
"Nothing",
"Anonymous",
"1.1.0",
"2019",
"ParentLayerGroup...",
"RGB*, GRAY*",
[
(PF_IMAGE,"image","Input image", None),
(PF_DRAWABLE,"drawable", "Input drawable", None),
(PF_STRING, "sPrefix", "Prefix for Groups", "G_"),
(PF_TOGGLE, "bRemove", "Remove Sufix in name file.jpg #1", False),
(PF_STRING, "sSufix", "Remove Sufix (regEx)", r"\.\w{1,6}( #\d+)$"),
(PF_SPINNER, "iOrderGroup", "Position layer in group", 1, (-999, 999, 1)),
(PF_TOGGLE, "bRoot", "All layers to Root", False),
],
[],
ParentLayerGroup,
menu="<Image>/Layer/Tools/"
)
main()