You are here

Invalid argument type for gimp-layer-translate

So, I'm trying to write a script that will duplicate an image, and stack all the layers on top of each other vertically, in a sort of filmstrip. So far, I've been able to everything working except the function to move the layers to the right place. It gets to the translate function, and then stops. It gives me an error, saying that the first argument is an invalid type, though I'm 99% sure that it's in the right format. I can't for the life of me figure out why this is happening, and I've spent the better part of the afternoon and evening trying. Here is the relevant code:

;define local variables
(index 1) ;utility variable

(layer ) ;the layer we want to work with at any given time
(listOfLayers '()) ;a list of all the layers in the new image (we'll fill it later)

);end of local variables

(while (< index theNumberOfLayers) ;while the utility var is less than number of layers

(set! listOfLayers (cdr (gimp-image-get-layers theImage))) ;set layers to a list of all the layers in theImage

(set! layer (car listOfLayers))

(gimp-layer-translate layer 0 (* index theOldImageHeight))

(gimp-image-lower-item-to-bottom theImage layer) ;lowers the layer to the bottom. we're done with it

(set! index (+ index 1)) ;increment the variable


(gimp-image-flatten theImage)
(gimp-display-new theImage)
(gimp-image-clean-all theImage)

Like I said, I've got everything working except this one function. I'm brand new to Scheme, though I have some programming experience. I have tried running the script on another computer with a different version of GIMP, and it returned the same error (I'm running GIMP 2.8 on Windows XP, by the way). If anyone could help me out, that would be greatly appreciated. I have searched high and low all over the internet, and I can't find this problem anywhere else. I've attached the source code, if anyone wants to take a look at it.

stack-layers-vertically.scm2.13 KB

Use '(car (gimp-image-get-active-layer theImage))' to get the active layer.

Use '(vector->list (cadr (gimp-image-get-layers theImage)))' to get the list of layers (in top to bottom order).

Thank you so much, that fixed it right up! Like I said, I'm brand new to Scheme, so there's still a lot of stuff I have yet to learn about the language. The solution to this problem is probably glaringly obvious to anyone who's been doing this for any amount of time. Thanks again!

Per your script at

If you replace

  (gimp-image-flatten theImage)


  (gimp-image-merge-visible-layers theImage EXPAND-AS-NECESSARY)

then you will avoid the loss of your layers' transparency.

Thank you, I was wondering how I was going to fix that. I've added it in, and it's working perfectly now! Thanks again!

Subscribe to Comments for "Invalid argument type for gimp-layer-translate"