I have an image with 78 layers where I need to cut the right hand half of the layer and paste it as a new layer immediately above the layer I am cutting it from. The selection needs also to be pasted at the very left of the new layer. Doing this manually it works perfectly by making my selection, cut then Edit>Paste As>New Layer. So if I cut from layer 9 the new layer will be inserted between the existing 9 and 10 and become the new layer 10.
By stealing others' code I have got my script to successfully cut but I'm having big problems getting it to paste as a new layer at the correct layer level and at the correct origin within the layer. At present it creates a new layer at the top of the stack and the pasted selection is in the same position as the layer from which it was cut rather than at the complete left as I would like it.
What would be great would be if I could, via the script access the menu item Edit>Paste As>New Layer but it doesn't seem possible to do that - or is it?
This is what I have so far:
; An attempt at cutting and pasting.
(define (script-fu-sel-cut2 img
;Paste into a new layer
; (gimp-edit-paste-as-new-layer) ;doesn't work drat!
(let* ((draw (car (gimp-image-get-active-drawable img))))
((= (car (gimp-drawable-is-layer draw)) 1)
(gimp-floating-sel-to-layer (car (gimp-edit-paste draw 1))))
((= (car (gimp-drawable-is-layer-mask draw)) 1)
(gimp-floating-sel-to-layer (car (gimp-edit-paste (car (gimp-image-get-active-layer img)) 1))))
((= (car (gimp-drawable-is-channel draw)) 1)
(gimp-floating-sel-to-layer (car (gimp-edit-paste (vector-ref (cadr (gimp-image-get-layers img)) 0) 1))))
; Complete the undo group
; Flush output
"Selection Cut 2"
"Copy the selection into the same layer"
SF-IMAGE "Image" 0
SF-DRAWABLE "Layer" 0)
Or would it be better to do it in python-fu? I haven't found any examples of python-fu scripts I can steal from to do even this so far yet.