; make some fucking layer group functionality ;----------------------------------- ; This script has been modified (September 12, 2008) by Miguel Oliveira (melocotone at gmail dot com) ; in order to make it possible to use sub-groupings in the layer names. ; Now the decision on selecting a layer or not is based on the ; first word of the current layer name starting with the same characters as the specified group name. ; Example: ; Current layer names Layer numbers (hypothetic) ; -------------------- ---------- ; "L2.S1.SS1 this layer" 2 ; "L2.S1.SS2 that layer" 5 ; "L2.S2 another layer" 3 ; "L1.S1.X1.P3 whatever layer" 7 ; "L1.S1.X2 another one" 1 ; ------------- ; The user wants to show all layers of select group "L2.S1" --shows layers --> 2,5 ; The user wants to show all layers of select group "L2" --shows layers --> 2,5,3 ; The user wants to show all layers of select group "L1.S1.X1.P3" --shows layers --> 7 ; ------- ; The notation inside the first word of the layer name is immaterial. I used here subgroups separated by ; a '.' but it could be a ':' or even no separator at all. ; The changes consist of a new function layerNameToSearchSize which is called in almost all scripts just ; after the line "(set! layer-name-group (car (strbreakup layer-name " ")))" of each of the scripts ; Changed also some 'foo' descriptions with somewhat more clear descriptions ; Miguel Oliveira ; The Netherlands ; September 12, 2008 ; ;----------------------------------- (define (layerNameToSearchSize currLayerName layerGroupName) ; substrings the name of the current layer to a name the same size as the passed layerGroupName (let* ( (lenToMatch (string-length layerGroupName)) (lenCurrLayer (string-length currLayerName)) (currName "") ) ; must check bounds here and do the right thing (if (< lenCurrLayer lenToMatch) (set! currName currLayerName) ) (if (not (< lenCurrLayer lenToMatch)) (set! currName (substring currLayerName 0 lenToMatch)) ; returns currName size-limited to the size of the layerGroupName ) (set! currName currName) );let ) (define (script-fu-gimp-layer-group-show image lgname) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "")) (gimp-image-undo-disable image) (set! layer-count 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (set! layer-name (car (gimp-layer-get-name layer))) (set! layer-name-group (car (strbreakup layer-name " "))) (set! layer-name-group (layerNameToSearchSize layer-name-group lgname)) ; added to allow for subgrouping (if (equal? layer-name-group lgname) ; compare the first part of the layer's name with lgname (gimp-layer-set-visible layer TRUE) ) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (define (script-fu-gimp-layer-group-hide image lgname) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "")) (gimp-image-undo-disable image) (set! layer-count 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (set! layer-name (car (gimp-layer-get-name layer))) (set! layer-name-group (car (strbreakup layer-name " "))) (set! layer-name-group (layerNameToSearchSize layer-name-group lgname)) ; added to allow for subgrouping (if (equal? layer-name-group lgname) ; compare the first part of the layer's name with lgname (gimp-layer-set-visible layer FALSE) ) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (define (script-fu-gimp-layer-group-showall image) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "")) (gimp-image-undo-disable image) (set! layer-count 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (gimp-layer-set-visible layer TRUE) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (define (script-fu-gimp-layer-group-hideall image) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "")) (gimp-image-undo-disable image) (set! layer-count 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (gimp-layer-set-visible layer FALSE) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (define (script-fu-gimp-layer-group-showallbut image lgname) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "")) (gimp-image-undo-disable image) (set! layer-count 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (set! layer-name (car (gimp-layer-get-name layer))) (set! layer-name-group (car (strbreakup layer-name " "))) (set! layer-name-group (layerNameToSearchSize layer-name-group lgname)) ; added to allow for subgrouping (if (not (equal? layer-name-group lgname)) ; compare the first part of the layer's name with lgname (gimp-layer-set-visible layer TRUE) ) (if (equal? layer-name-group lgname) ; compare the first part of the layer's name with lgname (gimp-layer-set-visible layer FALSE) ) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (define (script-fu-gimp-layer-group-hideallbut image lgname) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "")) (gimp-image-undo-disable image) (set! layer-count 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (set! layer-name (car (gimp-layer-get-name layer))) (set! layer-name-group (car (strbreakup layer-name " "))) (set! layer-name-group (layerNameToSearchSize layer-name-group lgname)) ; added to allow for subgrouping (if (not (equal? layer-name-group lgname)) ; compare the first part of the layer's name with lgname (gimp-layer-set-visible layer FALSE) ) (if (equal? layer-name-group lgname) ; compare the first part of the layer's name with lgname (gimp-layer-set-visible layer TRUE) ) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (define (script-fu-gimp-layer-group-drop-shadow image lgname offx offy blur color opacity resize) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "")) (set! layer-count 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (set! layer-name (car (gimp-layer-get-name layer))) (set! layer-name-group (car (strbreakup layer-name " "))) (set! layer-name-group (layerNameToSearchSize layer-name-group lgname)) ; added to allow for subgrouping (if (equal? layer-name-group lgname) ; compare the first part of the layer's name with lgname (script-fu-drop-shadow image layer offx offy blur color opacity resize) ) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) ) ) (define (script-fu-gimp-layer-group-link image lgname) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "")) (gimp-image-undo-disable image) (set! layer-count 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (set! layer-name (car (gimp-layer-get-name layer))) (set! layer-name-group (car (strbreakup layer-name " "))) (set! layer-name-group (layerNameToSearchSize layer-name-group lgname)) ; added to allow for subgrouping (if (equal? layer-name-group lgname) ; compare the first part of the layer's name with lgname (gimp-layer-set-linked layer TRUE) ) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (define (script-fu-gimp-layer-group-unlinkall image) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "")) (gimp-image-undo-disable image) (set! layer-count 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (set! layer-name (car (gimp-layer-get-name layer))) (set! layer-name-group (car (strbreakup layer-name " "))) ;(set! layer-name-group (layerNameToSearchSize layer-name-group lgname)) ; added to allow for subgrouping ;(if (equal? layer-name-group lgname) ; compare the first part of the layer's name with lgname (gimp-layer-set-linked layer FALSE) ;) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (define (script-fu-gimp-layer-group-sort image lgname) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "") (lglist '()) (layer-last 0) (layer-pos 0)) (gimp-image-undo-disable image) ; procure a list of all the layers (set! layer-count 0) (set! layer-last 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (set! layer-name (car (gimp-layer-get-name layer))) (set! layer-name-group (car (strbreakup layer-name " "))) (set! layer-name-group (layerNameToSearchSize layer-name-group lgname)) ; added to allow for subgrouping (if (equal? layer-name-group lgname) ; compare the first part of the layer's name with lgname ; this adds the layers to the list in reverse order (set! lglist (cons layer-count lglist))) (if (equal? layer-name-group lgname) (set! layer-last layer-count)) (set! layer-count (+ layer-count 1)) ) ; use this list to find each layer (set! lglist (cdr lglist)) (set! num-layers (length lglist)) ; don't start with the last layer, that's where we're moving the other layers to (set! layer-count 0) (while (< layer-count num-layers) ; get the position of the layer in the list (set! layer-pos (car lglist)) (set! lglist (cdr lglist)) ; get the layer (set! layer (aref layer-array layer-pos)) ; find out how many we need to move this (set! layer-pos (- layer-last layer-pos)) (set! layer-pos (- layer-pos 1)) (set! layer-pos (- layer-pos layer-count)) (while (> layer-pos 0) ; move the layer down (gimp-image-lower-layer image layer) (set! layer-pos (- layer-pos 1)) ) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (define (script-fu-gimp-layer-group-movebelow image lgname drw) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "") (lglist '()) (layer-last 0) (layer-pos 0) (drw-pos 0) (layer-movecount 0)) (script-fu-gimp-layer-group-sort image lgname) (gimp-image-undo-disable image) ; procure a list of all the layers (set! layer-count 0) (set! layer-last 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (if (equal? layer drw) (set! drw-pos layer-count)) (set! layer-name (car (gimp-layer-get-name layer))) (set! layer-name-group (car (strbreakup layer-name " "))) (set! layer-name-group (layerNameToSearchSize layer-name-group lgname)) ; added to allow for subgrouping (if (equal? layer-name-group lgname) ; compare the first part of the layer's name with lgname ; this adds the layers to the list in reverse order (set! lglist (cons layer-count lglist))) (if (equal? layer-name-group lgname) (set! layer-last layer-count)) (set! layer-count (+ layer-count 1)) ) ; use this list to find each layer (set! num-layers (length lglist)) (set! layer-movecount (- drw-pos layer-last)) ;(set! layer-movecount (- layer-movecount 1)) (set! layer-count 0) (while (< layer-count num-layers) ; get the position of the layer in the list (set! layer-pos (car lglist)) (set! lglist (cdr lglist)) ; get the layer (set! layer (aref layer-array layer-pos)) ; find out how many we need to move this (set! layer-pos layer-movecount) (while (> layer-pos 0) ; move the layer down (gimp-image-lower-layer image layer) (set! layer-pos (- layer-pos 1)) ) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (define (script-fu-gimp-layer-group-moveabove image lgname drw) (let* ((layers (gimp-image-get-layers image)) (num-layers (car layers)) (layer-array (cadr layers)) (layer-count 0) (layer 0) (layer-name "") (layer-name-group "") (lglist '()) (layer-last 0) (layer-pos 0) (drw-pos 0) (layer-movecount 0)) (script-fu-gimp-layer-group-sort image lgname) (gimp-image-undo-disable image) ; procure a list of all the layers (set! layer-count 0) (set! layer-last 0) (while (< layer-count num-layers) ; check the first word in the name of each layer, if it matches lgname, perform the action (set! layer (aref layer-array layer-count)) (if (equal? layer drw) (set! drw-pos layer-count)) (set! layer-name (car (gimp-layer-get-name layer))) (set! layer-name-group (car (strbreakup layer-name " "))) (set! layer-name-group (layerNameToSearchSize layer-name-group lgname)) ; added to allow for subgrouping (if (equal? layer-name-group lgname) ; compare the first part of the layer's name with lgname ; this adds the layers to the list in reverse order (set! lglist (cons layer-count lglist))) (if (equal? layer-name-group lgname) (set! layer-last layer-count)) (set! layer-count (+ layer-count 1)) ) ; use this list to find each layer (set! num-layers (length lglist)) (set! layer-movecount (- layer-last drw-pos)) ;(set! layer-movecount (- layer-movecount 1)) (set! layer-count 0) (while (< layer-count num-layers) ; get the position of the layer in the list (set! layer-pos (car lglist)) (set! lglist (cdr lglist)) ; get the layer (set! layer (aref layer-array layer-pos)) ; find out how many we need to move this (set! layer-pos layer-movecount) (while (> layer-pos 0) ; move the layer down (gimp-image-raise-layer image layer) (set! layer-pos (- layer-pos 1)) ) (set! layer-count (+ layer-count 1)) ) (gimp-displays-flush) (gimp-image-undo-enable image) ) ) (script-fu-register "script-fu-gimp-layer-group-show" "/Layer Groups/Show Layer Group" "SHOW all layers having the 1st word of the layer name *STARTING* with the given Layer Group Name" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0 SF-STRING "Layer Group Name" "") (script-fu-register "script-fu-gimp-layer-group-hide" "/Layer Groups/Hide Layer Group" "HIDE all layers having the 1st word of the layer name *STARTING* with the given Layer Group Name" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0 SF-STRING "Layer Group Name" "") (script-fu-register "script-fu-gimp-layer-group-showall" "/Layer Groups/Show All Layers" "foo" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0) (script-fu-register "script-fu-gimp-layer-group-hideall" "/Layer Groups/Hide All Layers" "foo" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0) (script-fu-register "script-fu-gimp-layer-group-showallbut" "/Layer Groups/Show All Layers But Group" "SHOW all layers *NOT* having the 1st word of the layer name *STARTING* with the given Layer Group Name" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0 SF-STRING "Layer Group Name" "") (script-fu-register "script-fu-gimp-layer-group-hideallbut" "/Layer Groups/Hide All Layers But Group" "HIDE all layers *NOT* having the 1st word of the layer name *STARTING* with the given Layer Group Name" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0 SF-STRING "Layer Group Name" "") (script-fu-register "script-fu-gimp-layer-group-drop-shadow" "/Layer Groups/Lighting and Shadows/Layer Group Drop Shadow" "Add a drop shadow to the selected region (or alpha)" "Sven Neumann " "Sven Neumann" "1999/12/21" "RGB* GRAY*" SF-IMAGE "Image" 0 SF-STRING "Layer Group Name" "" SF-ADJUSTMENT _"Offset X" '(8 -4096 4096 1 10 0 1) SF-ADJUSTMENT _"Offset Y" '(8 -4096 4096 1 10 0 1) SF-ADJUSTMENT _"Blur radius" '(15 0 1024 1 10 0 1) SF-COLOR _"Color" "black" SF-ADJUSTMENT _"Opacity" '(80 0 100 1 10 0 0) SF-TOGGLE _"Allow resizing" TRUE ) (script-fu-register "script-fu-gimp-layer-group-link" "/Layer Groups/Link Layer Group" "LINK all layers having the 1st word of the layer name *STARTING* with the given Layer Group Name" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0 SF-STRING "Layer Group Name" "") (script-fu-register "script-fu-gimp-layer-group-unlinkall" "/Layer Groups/Unlink All" "UNLINK all layers" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0) (script-fu-register "script-fu-gimp-layer-group-sort" "/Layer Groups/Sort Layer Group Down" "Move all layers in a group together in the layer list (not alphabetical), to the bottom-most layer in the group" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0 SF-STRING "Layer Group Name" "") (script-fu-register "script-fu-gimp-layer-group-movebelow" "/Layer Groups/Move Layer Group Below..." "Move the layer group below a specified layer" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0 SF-STRING "Layer Group Name" "" SF-DRAWABLE "Layer to move below" 0) (script-fu-register "script-fu-gimp-layer-group-moveabove" "/Layer Groups/Move Layer Group Above..." "Move the layer group above a specified layer" "Joseph Miller " "2008, Joseph Miller" "Thu Mar 20 16:48:26 2008" "RGBA RGB INDEXED*" SF-IMAGE "Image" 0 SF-STRING "Layer Group Name" "" SF-DRAWABLE "Layer to move below" 0)